使用STM32F103TB,中密度器件,裸机,各位大大给看看
int main(void)
{
/*!< At this stage the microcontroller clock setting is already configured,
this is done through SystemInit() function which is called from startup
file (startup_stm32f10x_xx.s) before to branch to application main.
To reconfigure the default setting of SystemInit() function, refer to
system_stm32f10x.c file
*/
uint8 i = 0;
uint32 code = 0;
PeriphClkEnable();
NVIC_Configuration();
PinCfg();
Timer2Init();
void PeriphClkEnable(void)
{
/* DMA clock enable */
RCC_AHBPeriphClockCmd(RCC_AHBPeriph_DMA1, ENABLE);
RCC_APB2PeriphClockCmd( RCC_APB2Periph_GPIOA
| RCC_APB2Periph_GPIOB
// | RCC_APB2Periph_GPIOC
| RCC_APB2Periph_GPIOD
// | RCC_APB2Periph_GPIOE
| RCC_APB2Periph_AFIO
| RCC_APB2Periph_USART1
// | RCC_APB2Periph_ADC1
// | RCC_APB2Periph_TIM1
, ENABLE);
RCC_APB1PeriphClockCmd( RCC_APB1Periph_USART2
// | RCC_APB1Periph_USART3
// | RCC_APB1Periph_UART4
// | RCC_APB1Periph_UART5
// | RCC_APB1Periph_I2C1
// | RCC_APB1Periph_I2C2
// | RCC_APB1Periph_DAC
| RCC_APB1Periph_TIM2
, ENABLE);
}
void NVIC_Configuration(void)
{
NVIC_InitTypeDef NVIC_InitStructure;
/* Enable the TIM2 global Interrupt */
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 Timer2Init(void)
{
// NVIC_InitTypeDef NVIC_InitStructure;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
// NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);
//
// NVIC_InitStructure.NVIC_IRQChannel = TIM2_IRQn;
// NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelSubPriority = 1;
// NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
// NVIC_Init(&NVIC_InitStructure);
TIM_TimeBaseStructure.TIM_Period = F_MY / 2; /* 设置自动重载寄存器值为最大值 */
TIM_TimeBaseStructure.TIM_Prescaler = (uint16)PRESCALER - 1; /* 计数频率为主频 / PRESCALER */
TIM_TimeBaseStructure.TIM_ClockDivision = 0;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM2, &TIM_TimeBaseStructure);
TIM_ARRPreloadConfig(TIM2, ENABLE);
TIM_ClearITPendingBit(TIM2, TIM_IT_Update);
TIM_ITConfig(TIM2, TIM_IT_Update , ENABLE);//开启计数中断
/* TIM2 enable counter */
TIM_Cmd(TIM2, ENABLE);//开启时钟
}
void TIM2_IRQHandler(void)
{
if(TIM_GetITStatus(TIM2,TIM_IT_Update)!=RESET)
{
TIM_ClearITPendingBit(TIM2,TIM_IT_Update);
// TIM_Cmd(TIM2, DISABLE);
// printf("\n\r0x%08x", 0x12345678);
Flag = 1;
}
}
|
中断向量表在哪里?