GPIO 输入—按键检测
来源:互联网 发布:组策略隐藏网络配置 编辑:程序博客网 时间:2024/05/22 09:20
这里要用到一定的模电知识。电容两端电压不能突变,电感两端电流不能突变。这里利用了电容的放电延时实现硬件消抖。按键按下会有抖动,波形有毛刺,使得高低电平显现不明显,而按键按下时,电容放电一下,马上又被充电,此时电容两端的电压不会突然变化,这个延时时间恰好可以达到消抖作用。
这里需要使用一个固件库函数:
/** * @brief Reads the specified input port pin. * @param GPIOx: where x can be (A..K) to select the GPIO peripheral for STM32F405xx/407xx and STM32F415xx/417xx devices * x can be (A..I) to select the GPIO peripheral for STM32F42xxx/43xxx devices. * x can be (A, B, C, D and H) to select the GPIO peripheral for STM32F401xx devices. * @param GPIO_Pin: specifies the port bit to read. * This parameter can be GPIO_Pin_x where x can be (0..15). * @retval The input port pin value. */uint8_t GPIO_ReadInputDataBit(GPIO_TypeDef* GPIOx, uint16_t GPIO_Pin){ uint8_t bitstatus = 0x00; /* Check the parameters */ assert_param(IS_GPIO_ALL_PERIPH(GPIOx)); assert_param(IS_GET_GPIO_PIN(GPIO_Pin)); if ((GPIOx->IDR & GPIO_Pin) != (uint32_t)Bit_RESET) { bitstatus = (uint8_t)Bit_SET; } else { bitstatus = (uint8_t)Bit_RESET; } return bitstatus;}
在第一次使用这个函数的时候,我没有理解到位,一看到定义bitstatus=0x00,就以为返回的是个八位端口的值,其实这个返回值只有0或者1两种结果。
/**
* @brief GPIO Bit SET and Bit RESET enumeration
*/
typedef enum
{
Bit_RESET = 0,
Bit_SET
}BitAction;
在这个枚举中,可以知道,读取IO的数据只可能是0或者1。
阅读全文
0 0
- GPIO 输入—按键检测
- 按键输入-GPIO输入
- 第12章 GPIO输入-按键检测—零死角玩转STM32-F429系列
- stm8 GPIO按键输入
- 按键实验(GPIO输入)
- atmega8 例程:按键输入检测
- 按键检测是否输入数字
- 4、树莓派3 Model B ——— 树莓派按键控制LED(GPIO输入模式)
- 树莓派 Learning 003 — GPIO 002 输入模式 — 按键控制LED
- arm7 力天电子lpc2148 GPIO之按键输入试验
- GPIO输出-----点灯(输出)和按键(输入)
- 按键的编程—中断检测按键
- GPIO按键处理流程
- 7620 Reset按键GPIO
- GPIO端口按键中断
- Linux下使用C语言进行检测按键的输入
- 检测按键
- 检测按键
- Vue+axios 实现http拦截及路由拦截实例
- 程序员最核心的竞争力是什么?
- android隐藏标题栏
- java 独立存储线程变量技术——ThreadLocal
- 利用CombineFileInputFormat合并小文件
- GPIO 输入—按键检测
- protobuf入门教程(四):repeated限定修饰符
- 数据类型及数据结构资料
- weblogic被root重启后出现 java.lang.ClassCastException
- vue2.0之axios使用详解(一)
- Nginx增加自定义域名配置服务
- 51NOD 1806 wangyurzee的树(容斥原理 + 组合数学)
- Array() 对象
- 生产者消费者模型