u8 ReadKey(void)
{
u8 KeyTemp = 0;
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_7) == Bit_RESET) { KeyTemp = SW_SET; }
if(GPIO_ReadInputDataBit(GPIOC,GPIO_Pin_6) == Bit_RESET) { KeyTemp = SW_UP; }
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_14) == Bit_RESET) { KeyTemp = SW_OK; }
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_15) == Bit_RESET) { KeyTemp = SW_DOWN;}
if(GPIO_ReadInputDataBit(GPIOB,GPIO_Pin_11) == Bit_RESET) { KeyTemp = SW_SW;}
return KeyTemp;
}
void KeyPrcoess(void)
{
static u8 KeyValueTemp = 0;
static u8 KeyLastTemp = 0;
static u8 KeyFiliterCnt = 0;
if(KeyScanCnt1ms > 10)
{
KeyScanCnt1ms = 0;
KeyLastTemp = KeyValueTemp;
KeyValueTemp = ReadKey();
if(KeyValueTemp != 0)
{
if(KeyFiliterCnt < 200)KeyFiliterCnt++;
else
{
KeyValue = KeyLastTemp;
}
}
else
{
if(KeyFiliterCnt > 1 && KeyFiliterCnt != 200)
{
KeyValue = KeyLastTemp;
}
KeyFiliterCnt = 0;
}
}
} |