使用定时器0中断实现LED1秒的流水灯
#include <reg52.h>
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;
}
}
版权声明:本文为CSDN博主「1N4007」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/qq_56894255/article/details/121450990
暂无评论