#include
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit led1 = P1^2;
sbit led2 = P1^3;
void Delay(unsigned int x)
{
unsigned int i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
//KEY1按一下LED1亮 再按一下LED1灭
//KEY2按下LED2亮 LED1灭
main()
{
while(1) {
if (!key2) { led1 = 1; led2 = 0;}
else {
if(!key1) {
Delay(10);
if(!key1) {
while(!key1);
led1 = ~led1;
} } } }
}
//--------------------------------
#include
sbit key1 = P1^0;
sbit key2 = P1^1;
sbit led1 = P1^2;
sbit led2 = P1^3;
void Delay(unsigned int x)
{
unsigned int i, j;
for(i = 0; i < x; i++) for(j = 0; j <= 148; j++);
}
main()
{
while(1) {
if(!key1) {
Delay(10);
if(!key1) {
while(!key1);
led1 = ~led1;//KEY1按一下LED1亮 再按一下LED1灭
} }
if(!key2) {
Delay(10);
if(!key2) {
while(!key2) led1 = 1; //按下KEY2时LED1灭
led2 = ~led2;//KEY2也是这样
} }
}
}