想要使用TIM4进行定时,但无法进入中断,改成TIM2却可以
void TIM4_Config(void) {
RCC_APB1PeriphClockCmd(RCC_APB1Periph_TIM4 , ENABLE);
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
TIM_TimeBaseStructure.TIM_Period = 10000 - 1;
TIM_TimeBaseStructure.TIM_Prescaler = 7200 - 1;
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1;
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
TIM_TimeBaseInit(TIM4 , &TIM_TimeBaseStructure);
TIM_ITConfig(TIM4 , TIM_IT_Update, ENABLE);
NVIC_InitTypeDef NVIC_InitStructure;
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_0);
NVIC_InitStructure.NVIC_IRQChannel = TIM4_IRQn;
NVIC_InitStructure.NVIC_IRQChannelPreemptionPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelSubPriority = 0;
NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
NVIC_Init(&NVIC_InitStructure);
TIM_Cmd(TIM4 , ENABLE);
}
=====================================================
=====================================================
#include "stm32f10x.h" // Device header
#include "General_Init.h"
#include "OLED.h"
#include "Timer_Init.h"
uint16_t count = 0;
int main() {
OLED_Init();//OLED初始化
while(1) {
OLED_ShowNum(1 , 1 , count , 4);
}
}
void TIM4_IRQHandler(void) {
if(TIM_GetITStatus(TIM4 , TIM_IT_Update) != RESET) {
count = count++;
TIM_ClearITPendingBit(TIM4 , TIM_IT_Update);
}
}
|