bug1:
对应代码
void EXTI9_5_IRQHandler(void)
{
if(EXTI_GetITStatus(EXTI_Line5) == SET){//由中断4触发
TIM_SetCounter(TIM2,0);//定时器计数清零
TIM_Cmd(TIM2,ENABLE);//开启定时器
while(GPIO_ReadInputDataBit(GPIOA,Echo)) {flag=1;printf("%d\r\n",flag);flag=0;};
TIM_Cmd(TIM2,DISABLE);//关闭定时器
//Distance= TIM_GetCounter(TIM2)*340/400;// distance = t*340/2 t = count*1/20000 1m=100cm 距离计算
//Distance= TIM_GetCounter(TIM2)*340/200.00;
Distance= TIM_GetCounter(TIM2);
EXTI_ClearITPendingBit(EXTI_Line5);//清除LINE4上的中断标志位
}
}
|