#include <reg52.h>
unsigned char count;
bit fg;
void main(void)
{
unsigned char i;
TMOD=0x01;
TH0=0xa0;
TL0=0xff;
ET0=1;
EA=1;
TR0=1;
while(1)
{
if(fg)
{
for(i=0; i<255; i++)
{
if(i>count)
P0 = 0x00;
else P0 = 0xff;
}
}
else
{
for(i=0; i<255; i++)
{
if(i<count)
P0 = 0x00;
else P0 = 0xff;
}
}
}
}
void timer0() interrupt 1
{
TH0=0xa0;
TL0=0xff;
count++;
if(count==255)
{fg=~fg;count=0;}
}
文章评论(0条评论)
登录后参与讨论