STM32 定时器如何设置启动后只触发一次中断:
//放到主函数的初始化中初始化
void Timer1CountInitial(void)
{
//定时=36000/72000x2=0.001s=1ms;
TIM_TimeBaseInitTypeDef TIM_TimeBaseStructure;
///////////////////////////////////////////////////////////////
RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1, ENABLE);
TIM_TimeBaseStructure.TIM_Period = 100-1;//自动重装值(此时改为100ms)
TIM_TimeBaseStructure.TIM_Prescaler = 7200-1;//时钟预分频
TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;//向上计数
TIM_TimeBaseStructure.TIM_ClockDivision = TIM_CKD_DIV1; //时钟分频1
TIM_TimeBaseStructure.TIM_RepetitionCounter = 0;
TIM_TimeBaseInit(TIM1,&TIM_TimeBaseStructure);
TIM_ClearFlag(TIM1,TIM_FLAG_Update);
TIM_ITConfig(TIM1,TIM_IT_Update,ENABLE);
TIM_Cmd(TIM1, ENABLE);
}
void TIM1_UP_IRQHandler(void)
{
if (TIM_GetITStatus(TIM1, TIM_IT_Update) != RESET)
{
//清除标志位 TIM_ClearFlag(TIM1,TIM_IT_Update);
}
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>