想试下定时器是否能正常用,编译时无错误,下载到芯片后进行单步调试,发现执行完 NVIC_Init(&NVIC_InitStructure);这句后就不往下执行了,请教各位老师啥问题?? #include "stm32f10x.h" unsigned int TimingDelay; void Delay(unsigned int x) { TimingDelay=x; while(TimingDelay--); } 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 | RCC_APB2Periph_AFIO,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(TIM3,ENABLE);//使能定时器 //使能TIM2中断 NVIC_InitTypeDef NVIC_InitStructure; NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;//选择TIM2全局中断 NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 2; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); while(1); } |
回复:定时器问题??
"stm32f10x_tim.C"
你加了上面这 文件了吗?
回复:定时器问题??
"stm32f10x_tim.C"
你加了上面这 文件了吗?