|
参照3.0库写的例程为何只能进入TIM_IT_Update而不能进入TIM_IT_CC1
右边对应3.0库代码:
void Tim2_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_OCInitTypeDef TIM_OCInitStructure;
TIM_TimeBaseStructure.TIM_Period = 5000;// 1us * 50 000 = 50ms;TIM_TimeBaseStructure.TIM_Period = 65535;
TIM_TimeBaseStructure.TIM_Prescaler = 35;// 36mhz /36 = 1mhz, =1us TIM_TimeBaseStructure.TIM_Prescaler = 0;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;// TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;// TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);// TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
/* Prescaler configuration */
TIM_PrescalerConfig(TIM2, 256, TIM_PSCReloadMode_Immediate);// TIM_PrescalerConfig(TIM2, 4, TIM_PSCReloadMode_Immediate);
/* Output Compare Timing Mode configuration: Channel1 */
TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;
TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 500;// TIM_OCInitStructure.TIM_Pulse = CCR1_Val; __IO uint16_t CCR1_Val = 49152;
TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;
TIM_OC1Init(TIM2, &TIM_OCInitStructure);
TIM_OC1PreloadConfig(TIM2, TIM_OCPreload_Disable);
/* TIM IT enable */
TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_Update, ENABLE);// TIM_ITConfig(TIM2, TIM_IT_CC1 | TIM_IT_CC2 | TIM_IT_CC3 | TIM_IT_CC4, ENABLE);我没有使用cc2,cc3,cc4
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);
}
中断处理
void TIM2_IRQHandler(void)
{
uint8_t b;
b=10;
b=b+1;
#ifdef _DEBUG_
printf("TIM2_IRQHnadler Success!\n");
#endif
if (TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET)
{
#ifdef _DEBUG_
printf("TIM2_IRQHnadler_Update Success!\n");
#endif
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
}
if (TIM_GetITStatus(TIM2, TIM_IT_CC1) != RESET)
{
#ifdef _DEBUG_
printf("TIM2_IRQHnadler_CC1 Success!\n");
#endif
TIM_ClearITPendingBit(TIM2, TIM_IT_CC1);
TIM_Cmd(TIM2, DISABLE);
}
}
keil4.12 调试结果
-
-
ex_timebase.JPG
(80.05 KB)
|
|