按键1控制亮,按键2控制灭
#include<reg52.h>
#define uint unsigned int
#define uchar unsigned char
sbit K1=P3^4;
sbit K2=P3^5;
void delay(uint z)
{
uint x,y;
for(x=z;x>0;x--)
for(y=110;y>0;y--);
}
void key()
{
if(K1==0)
{
delay(5);
if(K1==0)
{
P1=0xff;
while(!K1);
}
}
if(K2==0)
{
delay(5);
if(K2==0)
{
P1=0xfe;
while(!K2);
}
}
}
void main()
{
while(1)
{
key();
}
} |