#include "stm32f4xx.h" void LED_init(void); void TIM2_init(void); int main(void){ LED_init(); TIM2_init(); while(1){ } } /**************************************************/ void LED_init(void){ GPIO_InitTypeDef GPIO_InitStruct; RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_GPIOD, ENABLE); GPIO_InitStruct.GPIO_Mode = GPIO_Mode_OUT; GPIO_InitStruct.GPIO_Pin = GPIO_Pin_12; GPIO_Init(GPIOD, &GPIO_InitStruct); } /**************************************************/ void TIM2_init(void){ TIM_TimeBaseInitTypeDef TIM_TimeBaseInitStruct; NVIC_InitTypeDef NVIC_InitStruct; RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE); TIM_TimeBaseInitStruct.TIM_CounterMode = TIM_CounterMode_Up; TIM_TimeBaseInitStruct.TIM_Period = (SystemCoreClock/2)/1 - 1; TIM_TimeBaseInitStruct.TIM_Prescaler = 0; TIM_TimeBaseInit(TIM2, &TIM_TimeBaseInitStruct); NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0); NVIC_InitStruct.NVIC_IRQChannel = TIM2_IRQn; NVIC_InitStruct.NVIC_IRQChannelCmd = ENABLE; NVIC_InitStruct.NVIC_IRQChannelSubPriority = 1; NVIC_Init(&NVIC_InitStruct); TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE); TIM_Cmd(TIM2, ENABLE); } /**************************************************/ void TIM2_IRQHandler (void){ if(TIM_GetITStatus(TIM2, TIM_IT_Update) != RESET){ TIM_ClearITPendingBit(TIM2, TIM_IT_Update); GPIO_ToggleBits(GPIOD, GPIO_Pin_12); } }