用的原子个的mini板,本来定时的50us,出来确实250us。头都大了。
这是我的定时器程序:
void TIM1_Int_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1,ENABLE);
TIM_DeInit(TIM1);
TIM_TimeBaseStructure.TIM_Period = 49;
TIM_TimeBaseStructure.TIM_Prescaler = 71;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1); //设置NVIC中断分组1: 1位抢占优先级,3位响应优先级
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 3;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ClearFlag(TIM1, TIM_FLAG_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM1,ENABLE);
}
void TIM1_UP_IRQHandler(void)
{
if(TIM_GetITStatus(TIM1,TIM_IT_Update) !=RESET )
{
LED1 = !LED1;
TIM_ClearITPendingBit(TIM1,TIM_IT_Update);
}
}
附上我的程序,希望各位朋友能解决,我们共同学习!谢谢!
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
---------------------------------
虽然从现象上看应该是定时器重复计数功能影响了,但系统复位后该值为0的;
个人认为TIM_DeInit(TIM1)后加上这个TIM_TimeBaseStructInit(&TIM_TimeBaseStructure)与初始化结构体后调用这个函数没有什么区别,欢迎讨论...
一周热门 更多>