各位大佬,我在编写TIM6基础时钟代码的时候,发现进不去中断,我仔细核对了代码没有发现问题,麻烦各位指导下,以下是具体代码- #include<stm32f10x.h>
- #define TIM6_IRQn 54
- static unsigned int time;
- void delay(uint16_t n)
- {
- int i,j;
- for(i=0;i<n;i++)
- for(j=0;j<8500;j++);
- }
- void tim_init()
- {
- TIM_TimeBaseInitTypeDef tim;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
- tim.TIM_Period = 1000-1;
- tim.TIM_Prescaler = 71;
- tim.TIM_ClockDivision = TIM_CKD_DIV1;
- tim.TIM_CounterMode = TIM_CounterMode_Up;
- tim.TIM_RepetitionCounter = 0;
-
- TIM_TimeBaseInit(TIM6,&tim);
- TIM_ClearFlag(TIM6,TIM_FLAG_Update);
- TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
- TIM_Cmd(TIM6,ENABLE);
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,DISABLE);
- }
- void nvic_init()
- {
- NVIC_InitTypeDef nvic;
- NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
- nvic.NVIC_IRQChannel =TIM6_IRQn;
- nvic.NVIC_IRQChannelPreemptionPriority = 0;
- nvic.NVIC_IRQChannelSubPriority = 3;
- nvic.NVIC_IRQChannelCmd= ENABLE;
- NVIC_Init(&nvic);
- }
- void led_init()
- {
- GPIO_InitTypeDef led_gpio;
- RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC| RCC_APB2Periph_AFIO,ENABLE);
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_Disable,ENABLE);
- GPIO_PinRemapConfig(GPIO_Remap_SWJ_JTAGDisable,ENABLE);
- led_gpio.GPIO_Pin = GPIO_Pin_13;
- led_gpio.GPIO_Mode = GPIO_Mode_Out_PP;
- led_gpio.GPIO_Speed = GPIO_Speed_50MHz;
- GPIO_Init(GPIOC,&led_gpio);
- }
- int main()
- {
- led_init();
- tim_init();
- nvic_init();
- GPIOC->BSRR = GPIO_Pin_13;
- RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6,ENABLE);
- //delay(1000);
- while(1){}
- }
- void TIM6_IRQHandler()
- {
- if(TIM_GetITStatus(TIM6,TIM_IT_Update) != RESET){
- time++;
- if(time >=1000)
- {
- time = 0;
- /*GPIOC->IDR = ~GPIOC->IDR & GPIO_Pin_13;
- if(GPIOC->ODR & GPIO_Pin_13)
- {
- GPIOC->BRR = GPIO_Pin_13;
- }else
- {GPIOC->BSRR = GPIO_Pin_13;}
- */
- GPIOC->BRR = GPIO_Pin_13;
- }
- TIM_ClearITPendingBit(TIM6,TIM_FLAG_Update);
- }
- }
|