51单片机 c语言 就是我现在在用4x4矩阵键盘 然后我一个按键是控制流水灯开始
然后如何写才能做到我按其他按键的时候马上执行其他按键控制的呢附上部分程序voidKEY();voidDelay(unsignedinti);voidmain(){whil...
然后如何写才能做到我按其他按键的时候马上执行其他按键控制的呢
附上部分程序
void KEY();
void Delay(unsigned int i);
void main()
{
while(1)
{
KEY();
}
}
void KEY()
{
unsigned char i=0;
unsigned char j=0;
unsigned char k=0;
unsigned char KEY_VALUE=0;
P3=0x0f;
i=P3;
if(i!=0x0f)
{Delay(1000);
P3=0X0F;
i=P3;
if(i!=0x0f)
{
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0xff;
k=i|j;
switch(k)
{
case 0xee:
{
KEY_VALUE=1;
break;
}
case 0xde:
{
KEY_VALUE=2;
break;
}
case 0xbe:
{
KEY_VALUE=3;
break;
}
case 0x7e:
{
KEY_VALUE=4;
break;
}
case 0xed:
{
KEY_VALUE=5;
break;
}
case 0xdd:
{
KEY_VALUE=6;
break;
}
case 0xbd:
{
KEY_VALUE=7;
break;
}
case 0x7d:
{
KEY_VALUE=8;
break;
}
case 0xeb:
{
KEY_VALUE=9;
break;
}
case 0xdb:
{
KEY_VALUE=10;
break;
}
case 0xbb:
{
KEY_VALUE=11;
break;
}
case 0x7b:
{
KEY_VALUE=12;
break;
}
case 0xe7:
{
KEY_VALUE=13;
break;
}
case 0xd7:
{
KEY_VALUE=14;
break;
}
case 0xb7:
{
KEY_VALUE=15;
break;
}
case 0x77:
{
KEY_VALUE=16;
break;
}
}
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0XFF;
k=i|j;
while(k!=0xff)
{
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0X00;
k=i|j;
}
}
}
switch(KEY_VALUE)
{
case 1:
{
deng();break;
}
case 2:
{
huxideng();break;
}
case 3:
{
shengrikuaile();break;
}
case 4:
{
LED3=~LED3;break;
}
case 5:
{
LED4=~LED4;break;
}
case 6:
{LED5=~LED5;break;}
case 7:
{LED6=~LED6;break;}
case 8:
{LED7=~LED7;break;}
case 9:
{LED0=~LED0;BUZZ=~BUZZ;break;}
case 10:
{LED1=~LED1;BUZZ=~BUZZ;break;}
case 11:
{LED2=~LED2;BUZZ=~BUZZ;break;}
case 12:
{LED3=~LED3;BUZZ=~BUZZ;break;}
case 13:
{LED4=~LED4;BUZZ=~BUZZ;break;}
case 14:
{LED5=~LED5;BUZZ=~BUZZ;break;}
case 15:
{LED6=~LED6;BUZZ=~BUZZ;break;}
case 16: {LED7=~LED7;BUZZ=~BUZZ;break;}
}
} 展开
附上部分程序
void KEY();
void Delay(unsigned int i);
void main()
{
while(1)
{
KEY();
}
}
void KEY()
{
unsigned char i=0;
unsigned char j=0;
unsigned char k=0;
unsigned char KEY_VALUE=0;
P3=0x0f;
i=P3;
if(i!=0x0f)
{Delay(1000);
P3=0X0F;
i=P3;
if(i!=0x0f)
{
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0xff;
k=i|j;
switch(k)
{
case 0xee:
{
KEY_VALUE=1;
break;
}
case 0xde:
{
KEY_VALUE=2;
break;
}
case 0xbe:
{
KEY_VALUE=3;
break;
}
case 0x7e:
{
KEY_VALUE=4;
break;
}
case 0xed:
{
KEY_VALUE=5;
break;
}
case 0xdd:
{
KEY_VALUE=6;
break;
}
case 0xbd:
{
KEY_VALUE=7;
break;
}
case 0x7d:
{
KEY_VALUE=8;
break;
}
case 0xeb:
{
KEY_VALUE=9;
break;
}
case 0xdb:
{
KEY_VALUE=10;
break;
}
case 0xbb:
{
KEY_VALUE=11;
break;
}
case 0x7b:
{
KEY_VALUE=12;
break;
}
case 0xe7:
{
KEY_VALUE=13;
break;
}
case 0xd7:
{
KEY_VALUE=14;
break;
}
case 0xb7:
{
KEY_VALUE=15;
break;
}
case 0x77:
{
KEY_VALUE=16;
break;
}
}
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0XFF;
k=i|j;
while(k!=0xff)
{
P3=0X0F;
i=P3;
P3=0XF0;
j=P3;
P3=0X00;
k=i|j;
}
}
}
switch(KEY_VALUE)
{
case 1:
{
deng();break;
}
case 2:
{
huxideng();break;
}
case 3:
{
shengrikuaile();break;
}
case 4:
{
LED3=~LED3;break;
}
case 5:
{
LED4=~LED4;break;
}
case 6:
{LED5=~LED5;break;}
case 7:
{LED6=~LED6;break;}
case 8:
{LED7=~LED7;break;}
case 9:
{LED0=~LED0;BUZZ=~BUZZ;break;}
case 10:
{LED1=~LED1;BUZZ=~BUZZ;break;}
case 11:
{LED2=~LED2;BUZZ=~BUZZ;break;}
case 12:
{LED3=~LED3;BUZZ=~BUZZ;break;}
case 13:
{LED4=~LED4;BUZZ=~BUZZ;break;}
case 14:
{LED5=~LED5;BUZZ=~BUZZ;break;}
case 15:
{LED6=~LED6;BUZZ=~BUZZ;break;}
case 16: {LED7=~LED7;BUZZ=~BUZZ;break;}
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |