MultiButton
MultiButton copied to clipboard
在C51平台使用中需要注意下,上电后就会触发一次按下或者抬起事件
开发环境如下:uvision V4.10

按键初始化函数需要修改下:

猜测是编译器有问题。
/**
- @brief Initializes the button struct handle.
- @param handle: the button handle strcut.
- @param pin_level: read the HAL GPIO of the connet button level.
- @param active_level: pressed GPIO level.
- @retval None / void button_init(struct Button handle, uint8_t(*pin_level)(), uint8_t active_level) { memset(handle, 0, sizeof(struct Button)); handle->event = (uint8_t)NONE_PRESS; handle->hal_button_Level = pin_level; handle->active_level = active_level; handle->btn_level = !active_level; // handle->btn_level = handle->hal_button_Level(); // Keil C51在这里不能调用这个函数,否则会出现令人费解的错误,如果读取到的点平为 // 高电平,这个函数里handle->btn_level会被设置为1,但是实际上handle所指向的 // 结构体中的btn_level还是0。!!! }