Thursday, August 16, 2012

Delay 20mSec PWM genration

20 msec delay PWM genration Program

#include
#define off 0
#define on 1
sbit pin7 = P1^7;                        // label pin7 is port 1 pin 7
main()
{
TMOD = 0x01;                         /* timer 0 mode 1, TH0TL0 = 16 bit register*/
while(1)                                     // keep repeating the following section
{
pin7 = on;                                 /* pin 7 to 5 volts, i.e. logic 1 and use timer 0 to generate delay*/
TL0 = 0xFF;                            // hex FF into TL0
TH0 = 0xB7;                            // hex B7 into TH0
TR0 = on;                                // start timer
while(!TF0);                            // wait here until TF0 = 1
TR0 = off;                              // stop timer
TF0 = off;                             // clear overflow flag
pin7 = off;                            /* pin 7 to 0 v0lts, i.e. logic 0, repeat timer delay*/
TH0 = 0xB7;                       // hex B7 into TH0
TL0 = 0xFF;                       // hex FF into TL0
TR0 = on;                           // start timer
while(!TF0);                       // wait here until TF0 = 1
TR0 = off;                          // stop timer
TF0 = off;                          // clear overflow flag
}
}

No comments:

Post a Comment