一个普通的定时器中断LED灯亮一秒的程序,可是单步调试执行完 NVIC_Init(&NVIC_InitStructure);就不往下走了,请教原因。
#include "stm32f10x.h"
void TIM3_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2,TIM_IT_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
GPIO_SetBits(GPIOC, GPIO_Pin_7);
}
}
int main(void)
{
SystemInit();
//配置IO口
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOC | RCC_APB2Periph_GPIOD | RCC_APB2Periph_GPIOE,ENABLE);//IO口使能设置
GPIO_InitTypeDef GPIO_InitStructure; //定义结构体
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_7;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOC, &GPIO_InitStructure);
//设置定时器2
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2,ENABLE);//打开TIM2外设时钟
TIM_TimeBaseStructure.TIM_Period = 10000;//1s
TIM_TimeBaseStructure.TIM_Prescaler = 7199;//7200分频
TIM_TimeBaseStructure.TIM_ClockDivision = 0;//设置时钟分割
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//设置计数方式为向下计数
TIM_TimeBaseInit(TIM2,&TIM_TimeBaseStructure);//初始化定时器2
TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE);//打开定时器2中断
TIM_Cmd(TIM2,ENABLE);//使能定时器
//使能TIM2中断
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); //选择中断组0
NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; //指定中断源,
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;//无先占优先级,从优先级为1
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
while(1);
}
|