我正在使用开关案例构建一个去抖动定时器。
我输入了"case 1",但它在if (in_1_timerTimeout)
之后从未继续,我不知道为什么。有人能找出缺了什么吗?
到目前为止,我已经检查了代码是否存在"case 0"并输入"case 1",但仅限于此。我有一种感觉,我可能把if (in_1_timerTimeout)
解释错了,所以我没有正确使用它。
#include "mcc_generated_files/mcc.h"
#include "stdbool.h"
unsigned long in_1_timer = 0;
unsigned long in_1_state = 0;
bool in_1_timerTimeout = false;
bool in_1 = false;
void myInterruptHandler(void)
{
}
void handleInputFilter(void)
{
switch (in_1_state)
{
case 0:
if (!in_button_GetValue())
{
in_1_timer = 1000;
in_1_timerTimeout = false;
in_1_state = 1;
}
break;
case 1:
if (!in_button_GetValue())
{
//programmet kører hertil, men kommer ikke videre til næste "if"
if (in_1_timerTimeout)
{
in_1_state = 2;
in_1 = true;
//out_LED_SetHigh();
}
} else in_1_state = 0;
break;
case 2:
if (in_button_GetValue())
{
in_1_timer = 1000;
in_1_timerTimeout = false;
in_1_state = 3;
}
break;
case 3:
if (in_button_GetValue())
{
if (in_1_timerTimeout)
{
in_1_state = 0;
in_1 = false;
//out_LED_SetLow();
}
} else in_1_state = 2;
break;
}
}
void main(void)
{
SYSTEM_Initialize();
while (1)
{
handleInputFilter();
// Add your application code
}
}
在给定的上下文中,我看不到in_1_timerTimeout
设置为true的任何地方。
因此,它将始终跳过if (in_1_timerTimeout)
,因为它保持为false。
我看不出你的switch语句有任何问题,它正常工作。