单片机C语言代码问题 这个按键消抖是如何实现的?

void ScanKey_Return()
{
static bit KeyPressFlag = 0;
static uchar KeyCnt = 0;
if (Key_Return == 0)
{
KeyPressFlag = 1; //按键按下标志
}
if (KeyPressFlag)
{
KeyCnt++; //延时计数
if (KeyCnt > DELAY_NUM && Key_Return) //上升沿
{
KeyCnt = 0;
KeyPressFlag = 0;
Key_Return_Flag = 1;
}
}
}

因为按键动作接触的时间比起芯片处理所需的时间周期多得去,而其他因素引起的抖动却没有这种特性,所以往往用多次重复或保持较长时间周期来确定是抖动还是按键动作;按键动作可能保持会有成千上万个周期。
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答