C51非阻塞延時(shí)流水燈
[導(dǎo)讀]#includeunsigned 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
#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定時(shí),11.0592Mhz晶振,延時(shí)50ms。





