keil4编译器,用的是定时器4的输出比较功能,定时器内容为计算输出脉冲数量
代码如下
void TIM4_IRQHandler(void)
{
u16 capture;
if(TIM_GetITStatus(TIM4, TIM_IT_CC1) != RESET)//捕获/比较中断1
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC1);//清除中断标志位
// TIM_Cmd(TIM1,ENABLE);
capture = TIM_GetCapture1(TIM4);
TIM_SetCompare1(TIM4, capture + CCR1_Val);
if(NumPulse++>=Num_PULE)
{
NumPulse = 0;
Cho_CHx=1;
//TIM_Cmd(TIM1, ENABLE);
GPIO_ResetBits(GPIOB, GPIO_Pin_6);//将端口置低
TIM_CCxCmd(TIM4,TIM_Channel_1, DISABLE);//通道一关断
TIM_ITConfig(TIM4, TIM_IT_CC1, DISABLE);//中断禁止
//NumPulse = 0;
TIM_Cmd(TIM4,DISABLE);
//TIM_Cmd(TIM3,ENABLE);
}
}
else if(TIM_GetITStatus(TIM4, TIM_IT_CC4) != RESET)//捕获/比较中断1
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC4);//清除中断标志位
// TIM_Cmd(TIM1,ENABLE);
capture = TIM_GetCapture4(TIM4);
TIM_SetCompare4(TIM4, capture + CCR1_Val);
if(NumPulse++>=Num_PULE)
{
NumPulse = 0;
Cho_CHx=2;
//TIM_Cmd(TIM1, ENABLE);
GPIO_ResetBits(GPIOB, GPIO_Pin_9);//将端口置低
TIM_CCxCmd(TIM4,TIM_Channel_4, DISABLE);//通道一关断
TIM_ITConfig(TIM4, TIM_IT_CC4, DISABLE);//中断禁止
TIM_Cmd(TIM4,DISABLE);
//TIM_Cmd(TIM3,ENABLE);
}
}
else if(TIM_GetITStatus(TIM4, TIM_IT_CC2) != RESET)//捕获/比较中断2
{
TIM_ClearITPendingBit(TIM4, TIM_IT_CC2);//清除中断标志位
capture = TIM_GetCapture2(TIM4);
TIM_SetCompare2(TIM4, capture + CCR1_Val);
if(NumPulse++>=Num_PULE)
{
NumPulse = 0;
Cho_CHx=4;
GPIO_ResetBits(GPIOB, GPIO_Pin_7);//将端口置低
TIM_CCxCmd(TIM4,TIM_Channel_2, DISABLE);//通道二关断
TIM_ITConfig(TIM4, TIM_IT_CC2, DISABLE);//中断禁止
TIM_Cmd(TIM4,DISABLE);
}
}
// else if(TIM_GetITStatus(TIM4, TIM_IT_CC3) != RESET)//捕获/比较中断3
// {
// TIM_ClearITPendingBit(TIM4, TIM_IT_CC3);//清除中断标志位
// capture = TIM_GetCapture3(TIM4);
// TIM_SetCompare3(TIM4, capture + CCR1_Val);
// if(NumPulse++>=Num_PULE)
// {
// NumPulse = 0;
// Cho_CHx=1;
// GPIO_ResetBits(GPIOB, GPIO_Pin_8);//将端口置低
// TIM_CCxCmd(TIM4,TIM_Channel_3, DISABLE);//通道三关断
// TIM_ITConfig(TIM4, TIM_IT_CC3, DISABLE);//中断禁止
// TIM_Cmd(TIM4,DISABLE);
// }
// }
}
加上屏蔽的那段代码,程序执行错误,不知为什么,求高手指教 |
|