在线时间2 小时
UID399675
ST金币0
蝴蝶豆0
注册时间2012-11-7
新手上路
- 最后登录
- 2019-3-18
|
a0a.1 0b0c
初始化:
void TIM1_Init(void)
{
TIM1_DeInit();
TIM1_TimeBaseInit(7,TIM1_COUNTERMODE_UP,65535,0);
TIM1_PrescalerConfig(7,TIM1_PSCRELOADMODE_IMMEDIATE);
TIM1_ClearITPendingBit(TIM1_IT_UPDATE);
TIM1_OC1Init(TIM1_OCMODE_TIMING, TIM1_OUTPUTSTATE_ENABLE, TIM1_OUTPUTNSTATE_ENABLE, 1000, TIM1_OCPOLARITY_HIGH, TIM1_OCNPOLARITY_HIGH, TIM1_OCIDLESTATE_SET, TIM1_OCNIDLESTATE_SET);
TIM1_OC1PreloadConfig(DISABLE);
TIM1_ITConfig(TIM1_IT_CC1,ENABLE);
TIM1_Cmd(ENABLE);
}
比较中断函数:
#ifdef _COSMIC_
@far @interrupt void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void)
#else /* _RAISONANCE_ */
void TIM1_UPD_OVF_TRG_BRK_IRQHandler(void) interrupt 11
#endif /* _COSMIC_ */
{
capture_data=TIM1_GetCounter();
if(TIM1_GetITStatus(TIM1_IT_CC1))
{
TIM1_SetCompare1((capture_data+256)); // TIM1_SetCompare1((capture_data+255));
TIM1_ClearITPendingBit(TIM1_IT_CC1);//RESET_CCR1_INT_FLAG;
LED_XOR;
}
}
经测试,中断函数中 TIM1_SetCompare1((capture_data+256));正确; TIM1_SetCompare1((capture_data+255));错误!
调用的结果是不一样的。也就是TIM1->CCR1H有可能不变的前提下,程序就会出问题了。不知道大家是否遇到如此奇怪现象! |
|