已经做出来了,刚开始没想到设置第4个条件,看看还有什么改进的,谢谢!
#include
sbit k1=P1^0;
sbit k2=P1^1;
sbit k3=P1^2;
sbit led1=P2^4;
sbit led2=P2^5;
sbit led3=P2^6;
unsigned char n;
void in()
{
k1=1;
k2=1;
k3=1;
if(!k1&k2&k3)
n=1;
if(k1&!k2&k3)
n=2;
if(k1&!k2&!k3)
n=3;
if(k1&k2&k3)
n=4;
}
void out()
{
switch(n)
{
case 1:led1=0;
led2=1;
led3=1;
break;
case 2:led1=1;
led2=0;
led3=0;
break;
case 3:led1=1;
led2=0;
led3=1;
break;
case 4:led1=1;
led2=1;
led3=1;
break;
default:break;
}
}
void main()
{
while(1)
{
in();
out();
}
}