51单片机C语言对键控双向流水灯编程。用两个按键,中端来做。

2024-11-03 06:33:41
推荐回答(2个)
回答1:

#include
#define uchar unsigned char
uchar num,temp,times,led;
t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
times++;
if(times>=10)
{
times=0;
P0=led;
if(key1==0){
num++;
num&=0x07;
}
else if(key2==0)
{
if(num>0)num--;
else(num=7;
}
led>>=num;
}
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
LED=0x0xfe;
num=0;
times=0;
while(1);
}

回答2:

可以用外部中断吗