我用STM32F103VET6的基本定时器TIM6产生一个200ms的方波用PD14输出,可是检查了很多遍程序始终进入不了中断,以下是我的程序,其实程序不难,但真心求助各位问题出在了哪?
#include "stm32f10x.h"
#include "stm32f10x_tim.h"
#include "misc.h"
#include "stm32f10x_gpio.h"
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
void RCC_Configuration(void);
void GPIO_Configuration(void);
void NVIC_Configuration(void);
void TIM6_Init(void);
int main(void)
{
RCC_Configuration();
GPIO_Configuration();
TIM6_Init();
NVIC_Configuration();
while (1)
{
}
}
void RCC_Configuration(void)
{
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM6, ENABLE);
RCC_APB2PeriphClockCmd(RCC_APB2Periph_GPIOD, ENABLE);
}
void TIM6_Init(void)
{
TIM_TimeBaseStructure.TIM_Prescaler = 36000 - 1;
TIM_TimeBaseStructure.TIM_Period = 400 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
TIM_Cmd(TIM6, ENABLE);
}
void GPIO_Configuration(void)
{
GPIO_InitTypeDef GPIO_InitStructure;
GPIO_InitStructure.GPIO_Pin = GPIO_Pin_14;
GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
GPIO_Init(GPIOD, &GPIO_InitStructure);
GPIO_ResetBits(GPIOD,GPIO_Pin_14);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_1);
NVIC_InitStructure.NVIC_IRQChannel = TIM6_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0x00;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0x01;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_ITConfig(TIM6,TIM_IT_Update,ENABLE);
}
void TIM6_IRQHandler(void)
{
if(TIM_GetITStatus(TIM6,TIM_IT_Update) == SET);
{
if((GPIO_ReadInputDataBit(GPIOD,GPIO_Pin_14))==0)
{
GPIO_SetBits(GPIOD,GPIO_Pin_14);
}
else
{
GPIO_ResetBits(GPIOD,GPIO_Pin_14);
}
TIM_ClearITPendingBit(TIM6,TIM_IT_Update);
}
}
一周热门 更多>