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;
}
}
}
你的描述不是很清楚,我按照我的理解写的。