C51单片机按下独立按键怎样实现能够切换流水灯或者是跑马灯的流动方向

2024-12-29 02:41:08
推荐回答(1个)
回答1:

/*单片机,用定时中断实现每隔0.2秒让接在P1口的8个小灯从左往右循环点亮。*/
#include
#include
#define uchar unsigned char
uchar a,b;
uchar b=1;
uchar a=0xfe;
void main()
{
EA=1;IT1=1;ET0=1;
TH0=-5000/256;
TL0=-5000%256;
TMOD=0x01;

TR0=1;
while(1)
{;}

}

void timer0(void) interrupt 1 using 1
{
TH0=-5000/256;
TL0=-5000%256;
b=b+1;

if(b==40)
{
b=0;
P1=a;
a=_crol_(a,1);
P1=a;
}
}