#include "key.h"
#include "delay.h"
#include "lcd.h"
vu8 FriNum; //定义全局变量
extern unsigned char KEY_Num; //Ôúμ÷óÃμÄÎļtÖD¶¨òå°′¼üoÅ諾ֱäá¿
KeyScanState_Typedef KeyScanState = KeyScanState_0; //¶¨òå°′¼üé¨Ãè×′ì¬Ã¶¾ù±ä
//·Çá¬DøIO¿ú¡¢2»í¬IO¿ú×é¶àᢰ′¼ü£¬°′¼üêy½Ïéù
/******************************************************************************
* oˉêyÃû : KeyScan
* oˉêyÃèêö : °′¼üé¨Ãè3ìDò
* êäèë2Îêy : ÎT
* êä3ö½á1û : ÎT
* ·μ»ØÖμ : °′¼ü¼üoÅ
******************************************************************************/
void KeyScan(void)
{
// KeyPortStatus = GPIO_ReadInputData(KeyPort) & KeyPortPin;//»ñè¡°′¼ü¶Ë¿ú×′ì¬
switch(KeyScanState) //½øèë×′쬻úá÷3ì
{
case KeyScanState_0: //×′ì¬1£oÅD¶ÏóD·ñ°′¼ü°′ÏÂ
{
if(KEY1==0 || KEY2==0 || KEY3==0 || KEY4==0|| KEY5==0|| KEY6==0
|| KEY7==0|| KEY8==0|| KEY9==0|| KEY0==0|| KEYPoint==0|| KEYStart==0)
KeyScanState = KeyScanState_1;//óD°′¼ü°′Ï£¬¸üDÂ×′쬱êÖ¾
break;
}
case KeyScanState_1: //×′ì¬2£oÅD¶ÏêÇ·ñ¶¶¶ˉ
{
if(KEY0==0 ||KEY1==0 || KEY2==0 || KEY3==0 || KEY4==0|| KEY5==0
|| KEY6==0|| KEY7==0|| KEY8==0|| KEY9==0
|| KEYPoint==0|| KEYStart==0 ) //·Ç¶¶¶ˉ£¬è·èÏ°′¼ü°′Ï£¬Ö′DDÏàó|2ù×÷
{
if(KEY0==0) KEY_Num=0;
if(KEY1==0) KEY_Num=1;
if(KEY2==0) KEY_Num=2;
if(KEY3==0) KEY_Num=3;
if(KEY4==0) KEY_Num=4;
if(KEY5==0) KEY_Num=5;
if(KEY6==0) KEY_Num=6;
if(KEY7==0) KEY_Num=7;
if(KEY8==0) KEY_Num=8;
if(KEY9==0) KEY_Num=9;
if(KEYPoint==0)KEY_Num=10;
if(KEYStart==0) KEY_Num=11;
KeyScanState = KeyScanState_2;//¸üDÂ×′쬱êÖ¾
}
else //¶¶¶ˉ£¬è·èÏ°′¼üÎ′°′Ï£¬¸üDÂ×′쬱êÖ¾
KeyScanState = KeyScanState_0;
break;
}
case KeyScanState_2: //×′ì¬3£oËéêÖ¼ì2a
{
if(KEY1==1 && KEY2==1 && KEY3==1 && KEY4==1&& KEY5==1&& KEY6==1
&& KEY7==1 && KEY8==1 && KEY9==1 && KEY0==1 && KEYPoint==1&& KEYStart==1)
{
KeyScanState = KeyScanState_0;
}
break;
}
}
}
void keycontrol(void)
{
// if(time_20ms_ok)
//{
// time_20ms_ok = 0;
KeyScan(); //按键扫描
switch(KEY_Num)
{
case 0: FriNum=0;break;
case 1: FriNum=1;break;
case 2: FriNum=2;break;
case 3: FriNum=3;break;
case 4: FriNum=4;break;
case 5: FriNum=5;break;
case 6: FriNum=6;break;
case 7: FriNum=7;break;
case 8: FriNum=8;break;
case 9: FriNum=9;break;
case 10: FriNum=10;break;
// case 11: FriNum=11;break;
// case 12: FriNum=12;break;
}
//}
}
此帖出自
小平头技术问答
1、case 下面不需要加大括号{};
2、if后面最好不要这么多个条件与
这个按键驱动写的太乱了,建议看看别人是怎么处理的
一周热门 更多>