//mode ---value 1:long press
// ---value 0:short press
uint8_t scankey(uint8_t mode)
{
static uint8_t press = 1;
if(mode) press = 1;
if(press||USER_KEY)
{
HAL_Delay(50);
press = 0;
if(USER_KEY) return(KEY_PRE);
}
else if(!USER_KEY)
{
press = 1;
}
return 0;
}
mian。c主函数中
printf("the init of uart success !!!\r\n");
static uint16_t i;
while(1)
{
if(scankey(0))
{
RED_TOG;
i++;
printf("i = %d\r\n",i);
HAL_Delay(500);
}
}
烧录进入测试效果如下图所示: