用定時器加中斷實現(xiàn)間隔1S的流水燈C程序
#include
#define uchar unsigned char
#define uint unsigned int
uchar aa,count,flag;
void main() //主函數(shù)
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
EA=1;
ET0=1;
TR0=1;
aa=0xfe; //賦初值11111110
while(1) //大循環(huán)
{
P1=aa;
if(flag==1) //延時500毫秒
{
aa=_crol_(aa,1);//將aa循環(huán)左移1位后再賦給aa
flag=0;
}
}
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
count++;
if(count==20)
{
count=0;
flag=1;
}
}
評論