/* 名称:K1-K4按键状态显示
说明:K1、K2按下时LED点亮,松开时熄灭,
*/
K3、K4按下并释放时LED点亮,再次按下并释放时熄灭;
#includereg51.h>
#defineucharunsignedchar
#defineuintunsignedint
sbitLED1=P0^0;
sbitLED2=P0^1;
sbitLED3=P0^2;
sbitLED4=P0^3;
sbitK1=P1^0;
sbitK2=P1^1;
sbitK3=P1^2;
sbitK4=P1^3;
//延时
voidDelayMS(uintx)
{
uchari;
while(x--)for(i=0;i120;i++);
}
//主程序
voidmain()
{
P0=0xff;
P1=0xff;
while(1)
{
LED1=K1;
LED2=K2;
if(K3==0)
{
while(K3==0);
LED3=~LED3;
}
if(K4==0)
{
while(K4==0);
LED4=~LED4;
}
DelayMS(10);
}
}