ShipCentralControl/Anjiehui7_DTU/User/gpio_key.c

40 lines
760 B
C
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#include "includes.h"
void Key_Open()
{
}
// 处理按键
void Key_Handler(void)
{
static uint32_t key_tick = 0;
uint32_t tick = GetTickCount();
uint8_t g_KeyVal = KEY_INVALID;
// 保存键值
uint8_t pe5 = LL_GPIO_IsInputPinSet(GPIOE, GPIO_PIN_5);
// 判断是否为低电平,排除干扰
if(LL_GPIO_IsInputPinSet(GPIOE, GPIO_PIN_5))
return;
// 防抖动300ms以内的连续按键丢弃
if((tick >= key_tick && tick - key_tick < 300) || (tick < key_tick && 0xFFFFFFFFul - key_tick + 1 + tick < 300))
return;
if(pe5 == 0)
{
//printf("\n----------- Key pe5 pressed -----------\n");
g_KeyVal = KEY_ALARMOFF;
}
if(g_KeyVal != KEY_INVALID)
{
key_tick = GetTickCount();
// 解除报警
if(g_KeyVal == KEY_ALARMOFF && IS_ALARM_ON())
KZ_ALARM_OFF();
}
}