C51非阻塞延时流水灯
扫描二维码
随时随地手机看文章
#include
unsigned char counter=0;
void delay()interrupt 1 using 1
{
TL0|=0x00;
TH0=0x4C;
counter++;
}
main()
{
unsigned char i=1;
TMOD=1;
TR0=1;
EA=1;
ET0=1;
TH0=0x4C;
TL0=0x00;
while(1)
{
if(counter==10)
{
counter=0;
P1=~i;
i<<=1;
if(i==0)
i=1;
}
}
}
采用T0方式1定时,11.0592Mhz晶振,延时50ms。