高级会员
- 积分
- 970
- 金钱
- 970
- 注册时间
- 2016-11-24
- 在线时间
- 156 小时
|
楼主 |
发表于 2016-12-29 09:17:37
|
显示全部楼层
可以啊,我开定时器3,中断里面就LED1闪烁,没有任何问题,主函数里面放TIM3_Int_Init(5000-1,8400-1); ,中断里:void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM3,TIM_IT_Update)==SET)
{
LED1=!LED1;//D
}
TIM_ClearITPendingBit(TIM3,TIM_IT_Update);
},定时器初始化函数就用原子哥的,
void TIM3_Int_Init(u16 arr,u16 psc)
{
TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStructure;
NVIC_InitTypeDef NVIC_InitStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM3,ENABLE); ///ê1ÄüTIM3ê±Öó
TIM_TimeBaseInitStructure.TIM_Period = arr; //×Ô¶ˉÖØ×°ÔØÖμ
TIM_TimeBaseInitStructure.TIM_Prescaler=psc; //¶¨ê±Æ÷·ÖÆμ
TIM_TimeBaseInitStructure.TIM_CounterMode=TIM_CounterMode_Up; //ÏòéϼÆêyÄ£ê½
TIM_TimeBaseInitStructure.TIM_ClockDivision=TIM_CKD_DIV1;
TIM_TimeBaseInit(TIM3,&TIM_TimeBaseInitStructure);
TIM_ITConfig(TIM3,TIM_IT_Update,ENABLE); //ÔêDí¶¨ê±Æ÷3¸üDÂÖD¶Ï
TIM_Cmd(TIM3,ENABLE); //ê1Äü¶¨ê±Æ÷3
NVIC_InitStructure.NVIC_IRQChannel=TIM3_IRQn; //¶¨ê±Æ÷3ÖD¶Ï
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority=0x02; //ÇàÕ¼óÅÏ輶2
NVIC_InitStructure.NVIC_IRQChannelSubPriority=0x00; //×óóÅÏ輶0
NVIC_InitStructure.NVIC_IRQChannelCmd=ENABLE;
NVIC_Init(&NVIC_InitStructure);
} |
|