小学生
最后登录1970-1-1
在线时间 小时
注册时间2021-10-8
|
.c文件
uint8_t Key_Scan(uint8_t mode)
{
static uint8_t key_up=1;
if(key_up&&(KEY1==0||KEY2==0||KEY3==0))
{
HAL_Delay(10);
key_up=0;
HAL_Delay(150);
if(KEY1==0)return KEY1_PRES;
else if(KEY2==0)return KEY2_PRES;
else if(KEY3==0)
return KEY3_PRES;
}
else if(KEY1==1||KEY2==1||KEY3==1)key_up=1;
return 0;
}
main.c文件
while (1)
{
switch(Key_Scan(0))
{
case KEY1_PRES:
HAL_GPIO_TogglePin(GPIOA,Relay1_Pin);
break;
case KEY2_PRES:
HAL_GPIO_TogglePin(GPIOA,Relay1_Pin);
break;
case KEY3_PRES:
HAL_GPIO_TogglePin(GPIOC,GPIO_PIN_12);
HAL_GPIO_TogglePin(GPIOA,GPIO_PIN_12);
break;
}
}
|
|