void KeyRead(void)
{
static unsigned char ucKeyStatus=KEY_SEARCH_STATUS;
unsigned char ucKeyValue=0;
unsigned char i=0;
/* 获取按键值 */
ucKeyValue=read_key();
KEY_READ_temp=ucKeyValue;
if(KEY==KEY_OK_DUAN)
{
KEY_Cnt++;
if(KEY_Cnt>KEY_COUNT)
{
KEY_Cnt=NULL;
KEY=KEY_OK_CHANG;
}
}
if(KEY==KEY_SET_DUAN)
{
KEY_Cnt++;
if(KEY_Cnt>KEY_COUNT)
{
KEY_Cnt=NULL;
KEY=KEY_SET_CHANG;
}
}
if(KEY==KEY_JIA_DUAN)
{
KEY_Cnt++;
if(KEY_Cnt>KEY_COUNT)
{
KEY_Cnt=NULL;
KEY=KEY_JIA_CHANG;
}
}
if(KEY==KEY_JIAN_DUAN)
{
KEY_Cnt++;
if(KEY_Cnt>KEY_COUNT)
{
KEY_Cnt=NULL;
KEY=KEY_JIAN_CHANG;
}
}
switch(ucKeyStatus)
{
/* 按键查询状态 */
case KEY_SEARCH_STATUS:
{
if(ucKeyValue!=0XFF)
{
ucKeyStatus=KEY_ACK_STATUS;
}
}
break;
/* 按键确认状态 */
case KEY_ACK_STATUS:
{
if(ucKeyValue==0XFF) //没有按键按下
{
ucKeyStatus=KEY_SEARCH_STATUS;
}
else//有按键按下
{
if(ucKeyValue ==OK)
{
KEY=KEY_OK_DUAN;
}
if(ucKeyValue ==SET)
{
KEY=KEY_SET_DUAN;
}
if(ucKeyValue ==JIA)
{
KEY=KEY_JIA_DUAN;
}
if(ucKeyValue ==JIAN)
{
KEY=KEY_JIAN_DUAN;
}
}
ucKeyStatus=KEY_REALEASE_STATUS;
}
break;
/* 按键释放状态 */
case KEY_REALEASE_STATUS:
{
if(ucKeyValue==0XFF) //没有按键按下
{
KEY_Cnt=NULL;
ucKeyStatus=KEY_SEARCH_STATUS;
if(KEY ==KEY_OK_DUAN)KEY=KEY_OK_SONG;
if(KEY ==KEY_SET_DUAN)KEY=KEY_SET_SONG;
if(KEY ==KEY_JIA_DUAN)KEY=KEY_JIA_SONG;
if(KEY ==KEY_JIAN_DUAN)KEY=KEY_JIAN_SONG;
}
}
break;
default:
break;
}
}
|