stc89c52rc单片机编程按钮1按下led1量5秒,按钮2按下LED2亮5秒,请高人编程

2024-12-02 05:32:28
推荐回答(1个)
回答(1):

#include
#define uchar unsigned char
sbit key1=P1^0
sbit key2=P1^1;
sbit led1=P1^4;
sbit led2=P1^5;
uchar cnt1,cnt2;
void t0isr() interrupt 1
{
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
cnt1++;
cnt2++;
if(cnt1>=100)led1=1;
if(cnt2>=100)led2=1;
}
main()
{
TMOD=0x01;
TH0=(65536-50000)/256;
TL0=(65536-50000)%256;
TR0=1;
ET0=1;
EA=1;
while(1)
    {
    if(key1==0)
        {
        while(key1==0);
        cnt1=0;
        led1=0;
        }
    if(key2==0)
        {
        while(key2==0);
        cnt2=0;
        led2=0;
        }
    }
}