51uwb.cn

标题: BP50的KEY按键为什么不管用? [打印本页]

作者: doufubin    时间: 昨天 20:07
标题: BP50的KEY按键为什么不管用?
本帖最后由 doufubin 于 2026-10-6 20:09 编辑

MX_GPIO_Init函数增加如下代码:
        GPIO_InitStruct.Pin =  GPIO_PIN_1;
        GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
        GPIO_InitStruct.Pull = GPIO_NOPULL;
        HAL_GPIO_Init(GPIOA, &GPIO_InitStruct);
在主循环中增加如下代码:
while (1) {
     button_val = HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_1);
     if (button_val) {
         HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_SET);
    } else {
         HAL_GPIO_WritePin(LED_GPIO_Port, LED_Pin, GPIO_PIN_RESET); //一直执行到这里
    }        
}
灯一直是灭的,什么原因?你们测试过这个KEY吗?确认可以用?





欢迎光临 51uwb.cn (https://www.51uwb.cn/) Powered by Discuz! X3.3