在tpad.c文件中,获取触摸按键的值(我理解为充电时间)用的是TPAD_Get_Val函数。如下:
[mw_shl_code=c,true]u16 TPAD_Get_Val(void)
{
TPAD_Reset();
while(TIM_GetFlagStatus(TIM5, TIM_IT_CC2) == RESET)
[/mw_shl_code]
[mw_shl_code=c,true] {
if(TIM_GetCounter(TIM5)>TPAD_ARR_MAX_VAL-500)return TIM_GetCounter(TIM5);
};
return TIM_GetCapture2(TIM5);
} [/mw_shl_code]
当把其中的while语句改为:
[mw_shl_code=c,true]while(TIM_GetITStatus(TIM5,TIM_IT_CC2)!=RESET)
[/mw_shl_code]
实验现象却一样。
我看了TIM_GetITStatus函数的实现,如下:
[mw_shl_code=c,true]ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, uint16_t TIM_IT)
{
ITStatus bitstatus = RESET;
uint16_t itstatus = 0x0, itenable = 0x0;
/* Check the parameters */
assert_param(IS_TIM_ALL_PERIPH(TIMx));
assert_param(IS_TIM_GET_IT(TIM_IT));
itstatus = TIMx->SR & TIM_IT;
itenable = TIMx->DIER & TIM_IT;
if ((itstatus != (uint16_t)RESET) && (itenable != (uint16_t)RESET))
{
bitstatus = SET;
}
else
{
bitstatus = RESET;
}
return bitstatus;
}[/mw_shl_code]
程序中没有操作DIER寄存器的函数,因而DIER的值为0X0,则bitstatus的值为RESET,永远不可能进入超时判断。
所以,while语句改为:while(TIM_GetITStatus(TIM5,TIM_IT_CC2)!=RESET)实验现象却一样的原因是:硬件没有出现过超时。也就是说,只要硬件没问题,那个while语句有没有就无所谓了。
不过,若真出现超时,while(TIM_GetFlagStatus(TIM5, TIM_IT_CC2) == RESET)才是正确的判断,
while(TIM_GetITStatus(TIM5,TIM_IT_CC2)!=RESET)就不是正确的判断了。
|