勾选固件库,选中:CMSIS>CORE;Device>Startup;>StdPeriph Drivers>EXTI;>Framework;>GPIO;>RCC;>TIM;等
#include "stm32f10x.h"
void TIM2_IRQHandler(void)
{
if (TIM_GetITStatus(TIM2, TIM_FLAG_Update) != RESET)
{
TIM_ClearITPendingBit(TIM2, TIM_FLAG_Update);
GPIO_Write(GPIOA, ~GPIO_ReadInputData(GPIOA));
}
}
int main()
{
GPIO_InitTypeDef GPIO_InitS;
NVIC_InitTypeDef NVIC_InitS;
TIM_TimeBaseInitTypeDef TIM_TBIS;
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM2, ENABLE);
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitS.NVIC_IRQChannel = TIM2_IRQn;
NVIC_InitS.NVIC_IRQChannelCmd = ENABLE;
NVIC_InitS.NVIC_IRQChannelSubPriority = 0;
NVIC_Init(&NVIC_InitS);
TIM_DeInit(TIM2);
TIM_TBIS.TIM_Period = 10000;
TIM_TBIS.TIM_Prescaler = 7200 - 1;
TIM_TBIS.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TBIS);
TIM_ITConfig(TIM2, TIM_IT_Update, ENABLE