...K1,K2,K3,K4分别接P1.0到P1.4口,灯D1接P2.0口,K1,K2,K3中一个开关...
发布网友
发布时间:2024-10-15 23:52
我来回答
共1个回答
热心网友
时间:2024-10-16 10:24
sbit Key1 = P0^1;
sbit Key2 = P0^2;
sbit Key3 = P0^3;
sbit Key4 = P0^4;
sbit LED = P2^0;
#define ON 1
#define OFF 0
unsigned char flag;
int main(void)
{
flag = OFF;
while (1)
{
if ((Key1|Key2|Key3)&& (flag == OFF)) ///灯处于熄灭状态时 任何按键可以点亮
{
LED = 1;
flag = ON;
}else{
LED = 0;
flag = OFF;
}
if (Key4 &&(flag == ON)) ///按下key4时 熄灭灯,且任何按键无法点亮灯
{
LED = 0;
flag = ON;
}
if (!Key4) ///松开 key4 可以灯可以重新被点亮
{
flag = OFF;
}
}
}
你的描述不是很清楚,我按照我的理解写的。