定时器1中断服务函数
//定时器1中断服务程序
void TIM1_CC_IRQHandler(void)
{
if((TIM1CH4_CAPTURE_STA&0X80)==0)//还未成功捕获
{
if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)
{
if(TIM1CH4_CAPTURE_STA&0X40)//已经捕获到高电平了
{
if((TIM1CH4_CAPTURE_STA&0X3F)==0X3F)//高电平太长了
{
TIM1CH4_CAPTURE_STA|=0X80;//标记成功捕获了一次
TIM1CH4_CAPTURE_VAL=0XFFFF;
}else TIM1CH4_CAPTURE_STA++;
}
}
if (TIM_GetITStatus(TIM1, TIM_IT_CC4) != RESET)//捕获 1 发生捕获事件
{
if(TIM1CH4_CAPTURE_STA&0X40) //捕获到一个下降沿
{
TIM1CH4_CAPTURE_STA|=0X80; //标记成功捕获到一次上升沿
TIM1CH4_CAPTURE_VAL=TIM_GetCapture4(TIM1);
TIM_OC4PolarityConfig(TIM1,TIM_ICPolarity_Rising);
//CC1P=0 设置为上升沿捕获
}else //还未开始,第一次捕获上升沿
{
TIM1CH4_CAPTURE_STA=0; //清空
TIM1CH4_CAPTURE_VAL=0;
TIM_SetCounter(TIM1,0);
TIM1CH4_CAPTURE_STA|=0X40; //标记捕获到了上升沿
TIM_OC4PolarityConfig(TIM1,TIM_ICPolarity_Falling);
//CC1P=1 设置为下降沿捕获
}
}
}
TIM_ClearITPendingBit(TIM1, TIM_IT_CC4|TIM_IT_Update); //清除中断标志位
}
|