[COLOR=#FF0000]#include <reg52.h>[/COLOR]
#include <stdio.h>
[COLOR=#FF0000]#define pw P2[/COLOR]
void pwm(unsigned char ms);
[COLOR=#008000]void main()[/COLOR]
{
[COLOR=#008000]pw=0x00;[/COLOR]
while(1)
{
unsigned char msec;
unsigned char nsec;
msec=100;
nsec=100-msec;
[COLOR=#FF0000] pw=0x01;[/COLOR]
pwm(msec);
pw=0x00;
pwm(nsec);
}
}
void pwm(unsigned char ms)
{
unsigned int i;
for(i=0;i<ms<i++)
{
TMOD=0x01;
TH0=0xFC;
TL0=0x67;
TR0=0x01;
while(TF0==0x00);
TR0=0x00;
TF0=0x00;
}
}