#include"stm32f10x.h" #include"stm32f10x_gpio.h" #include"stm32f10x_rcc.h" #include"misc.h" #include"stm32f10x_tim.h" #include"stm32f10x_conf.h" void gpio_Init(void); void nvic_Init(void); void TIM_Init(void) ; int main() { gpio_Init(); nvic_Init(); TIM_Init(); while(1) { GPIO_ResetBits(GPIOG, GPIO_Pin_13); GPIO_SetBits(GPIOG, GPIO_Pin_12); } } void gpio_Init(void) { GPIO_InitTypeDef GPIO_InitStructure; RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOG, ENABLE); GPIO_InitStructure.GPIO_Pin = GPIO_Pin_12 | GPIO_Pin_13; GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; GPIO_Init(GPIOG, &GPIO_InitStructure); } void nvic_Init(void) { NVIC_InitTypeDef NVIC_InitStructure; NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0; NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0; NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE; NVIC_Init(&NVIC_InitStructure); } void TIM_Init(void) { TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_ARRPreloadConfig(TIM2, ENABLE); TIM_DeInit(TIM2); //TIMx寄存器重设为缺省值 TIM_TimeBaseStructure.TIM_Period = 29999; TIM_TimeBaseStructure.TIM_Prescaler=7199; TIM_TimeBaseStructure.TIM_ClockDivision=TIM_CKD_DIV1; TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure); TIM_ITConfig(TIM2,TIM_IT_Update,ENABLE); TIM_ClearFlag(TIM2,TIM_FLAG_Update); TIM_Cmd(TIM2, ENABLE); //TIM2开启时钟 } void TIM2_IRQHandler(void) { GPIO_ResetBits(GPIOG, GPIO_Pin_12); GPIO_SetBits(GPIOG, GPIO_Pin_13); TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update); } |
RE:最简单的闪灯进不了中断
回复:最简单的闪灯进不了中断
仿真是否进入中断,另外,while里面一直在进行IO的操作,这个会影响的,而且速率又那么的快,连个延时都没有.
多谢管理员,学习一段时间回头看,情况是没开时钟,这个是致命的错误!!