跪求一个按键控制流水灯的单片机程序,要三种花样,且用reg52.h。急急急急!!!!

2024-11-01 21:23:43
推荐回答(1个)
回答1:

#include
#include
#define uchar unsigned char
sbit key=P1^0;
uchar led,time;
void t0isr() interrupt 1
{
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
switch(time)
    {
    case 0:P0=led;led=_crol_(led,1);break;
    case 1:P0=led;led=_cror_(led,1);brea;
    case 2:P0=led;led=~led;break;
    }
}
main()
{
TMOD=0x01;
TH0=(65536-60000)/256;
TL0=(65536-60000)%256;
TR0=1;
ET0=1;
EA=1;
led=0xfe;
while(1)
    {
    if(key==0)
        {
        while(key==0);
        time++;
        time%=3;
        if(time==0)led=0xfe;
        else if(time==1)led=0x7f;
        else led=0x55;
        }
    }
}