其实我想问一下,我建c8t6的工程,选用md的启动文件,为什么我定时器定时5ms,实际却是50ms,我延时500ms让LED闪烁,却发现是5s。这是为什么?不知道为什么,求解!代码如下
LED0=0;
delay_ms(500);
LED0=1;
delay_ms(500);
void Timer1_Init(void)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
NVIC_InitTypeDef NVIC_InitStructure;
TIM_DeInit(TIM1);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 49;//×Ô¶ˉÖØ×°3õÖμ£¬Ã¿200′ÎÖD¶Ïò»′Î 5MS
TIM_TimeBaseStructure.TIM_Prescaler = 7199;//pscÔ¤·ÖÆμ
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//ê±Öó2»·ÖÆμ
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInit(TIM1, & TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM1,ENABLE);//ê1ÄüTIMxÔúARRéÏμÄԤװÔؼÄ′æÆ÷
TIM_Cmd(TIM1,ENABLE);//ê1Äü¶¨ê±Æ÷
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE); //ê1Äü¶¨ê±Æ÷ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannel = TIM1_UP_IRQn;//éèÖÃí¨μàêy
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2;//Ö÷óÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//′óóÅÏ輶
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>