小编Cod*_*eOn的帖子

在 C 中切换去抖动逻辑

我遇到了 Ganssle关于开关去抖动的这段代码。代码似乎非常有效,我的几个问题可能非常明显,但我希望得到澄清。

  • 为什么他检查 10 毫秒的按钮按下时间和 100 毫秒的按钮释放时间。他不能只检查 10 毫秒的按下和释放吗?
  • 是从 main 每 5 毫秒轮询一次这个函数是执行它的最有效方法,还是我应该检查引脚中的中断,当有中断时,将引脚更改为 GPI 并进入轮询例程,在我们推断出值切换之后引脚回到中断模式?

#define CHECK_MSEC  5   // Read hardware every 5 msec
#define PRESS_MSEC  10  // Stable time before registering pressed
#define RELEASE_MSEC    100 // Stable time before registering released
// This function reads the key state from the hardware.
extern bool_t RawKeyPressed();

// This holds the debounced state of the key.
bool_t DebouncedKeyPress = false;

// Service routine called every CHECK_MSEC to …
Run Code Online (Sandbox Code Playgroud)

c embedded debouncing

2
推荐指数
1
解决办法
2万
查看次数

标签 统计

c ×1

debouncing ×1

embedded ×1