tim1定时器不进中断的问题,来看看,芯片stm32f051c8,程序配置如下

2019-03-23 18:13发布

tim1定时器的配置和中断配置如下,帮忙看看有什么问题
void TIM1_INT_Config(void)
{
  NVIC_InitTypeDef NVIC_InitStructure;

/* TIM1 ʱÖÓʹÄÜ */
  RCC_APB2PeriphClockCmd(RCC_APB2Periph_TIM1 , ENABLE);
  /*  TIM1 ÖжÏǶÌ×Éè¼Æ*/
  NVIC_InitStructure.NVIC_IRQChannel = TIM1_BRK_UP_TRG_COM_IRQn;
NVIC_InitStructure.NVIC_IRQChannel = TIM1_CC_IRQn;
  NVIC_InitStructure.NVIC_IRQChannelPriority = 1;
  NVIC_InitStructure.NVIC_IRQChannelCmd = ENABLE;
  NVIC_Init(&NVIC_InitStructure);
}

void TIM1_Toggle_Config(void)
{
  /* Time ¶¨Ê±»ù´¡ÉèÖÃ*/
TIM_TimeBaseStructure.TIM_Period = 65535;
  TIM_TimeBaseStructure.TIM_Prescaler = 0;
  TIM_TimeBaseStructure.TIM_ClockDivision = 0;
  TIM_TimeBaseStructure.TIM_CounterMode = TIM_CounterMode_Up;
  TIM_TimeBaseInit(TIM1, &TIM_TimeBaseStructure);
  
/* Ô¤·ÖƵÆ÷ÅäÖà */
  TIM_PrescalerConfig(TIM1, 47, TIM_PSCReloadMode_Immediate);
  /* ƵµÀ2µÄ±È½ÏÊä³öģʽÉèÖà */
  TIM_OCInitStructure.TIM_OCMode = TIM_OCMode_Timing;//TIM_OCMode_Toggle;//TIM_OCMode_PWM1;
  TIM_OCInitStructure.TIM_OCPolarity = TIM_OCPolarity_High;

//ʹÄÜƵµÀ2ÅäÖÃ
  TIM_OCInitStructure.TIM_OutputState = TIM_OutputState_Enable;
TIM_OCInitStructure.TIM_Pulse = 10000;//Puls_Val;
  TIM_OC2Init(TIM1, &TIM_OCInitStructure);
TIM_OC2PreloadConfig(TIM1, TIM_OCPreload_Disable);

  /* TIM ÖжÏʹÄÜ */
  TIM_ITConfig(TIM1, TIM_IT_CC2, ENABLE);

/* TIM1 ¼ÆËãÆ÷ʹÄÜ*/
  TIM_Cmd(TIM1, ENABLE);

  /* TIM1 Ö÷Êä³öʹÄÜ */
  TIM_CtrlPWMOutputs(TIM1, ENABLE);
}
此帖出自小平头技术问答
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
该问题目前已经被作者或者管理员关闭, 无法添加新回复
2条回答
越狱兔哥哥
1楼-- · 2019-03-24 02:32
/ LAIRENA
越狱兔哥哥
2楼-- · 2019-03-24 02:58
来看看啊

一周热门 更多>