使用定时器0中断实现LED1秒的流水灯
#include <>
typedef unsigned int u16;
typedef unsigned char u8;
u8 code LED[]={0xfe,0xfd,0xfb,0xf7,0xef,0xdf,0xbf,0x7f};
u16 time,i;
void timer0init()
{
TMOD=0x01;
ET0=1;
EA=1;
TR0=1;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
}
void main()
{
timer0init();
while(1);
}
void timer0() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
time++;
if(time==20)
{
P2=LED[i];
i++;
if(i==8)
{
i=0;
}
time=0;
}
}