⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 stm32f10x_tim1.c

📁 STM32下做的usb转RS232程序
💻 C
📖 第 1 页 / 共 5 页
字号:
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_SelectSlaveMode(u16 TIM1_SlaveMode)
{
  u32 tmpsmcr = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_SLAVE_MODE(TIM1_SlaveMode));

  tmpsmcr = TIM1->SMCR;

  /* Reset the SMS Bits */
  tmpsmcr &= SMCR_SMS_Mask;

  /* Select the Slave Mode */
  tmpsmcr |= TIM1_SlaveMode;

  TIM1->SMCR = (u16)tmpsmcr;
}

/*******************************************************************************
* Function Name  : TIM1_SelectMasterSlaveMode
* Description    : Sets or Resets the TIM1 Master/Slave Mode.
* Input          : - TIM1_MasterSlaveMode: specifies the TIM1 Master Slave Mode.
*                    This paramter can be one of the following values:
*                       - TIM1_MasterSlaveMode_Enable: synchronization between
*                         the current timer and its slaves (through TRGO).
*                       - TIM1_MasterSlaveMode_Disable: No action
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_SelectMasterSlaveMode(u16 TIM1_MasterSlaveMode)
{
  /* Check the parameters */
  assert_param(IS_TIM1_MSM_STATE(TIM1_MasterSlaveMode));

  /* Set or Reset the MSM Bit */
  *(vu32 *) SMCR_MSM_BB = TIM1_MasterSlaveMode;
}

/*******************************************************************************
* Function Name  : TIM1_EncoderInterfaceConfig
* Description    : Configures the TIM1 Encoder Interface.
* Input          : - TIM1_EncoderMode: specifies the TIM1 Encoder Mode.
*                    This parameter can be one of the following values:
*                       - TIM1_EncoderMode_TI1: Counter counts on TI1FP1 edge
*                         depending on TI2FP2 level.
*                       - TIM1_EncoderMode_TI2: Counter counts on TI2FP2 edge
*                         depending on TI1FP1 level.
*                       - TIM1_EncoderMode_TI12: Counter counts on both TI1FP1 and
*                         TI2FP2 edges depending on the level of the other input.
*                  - TIM1_IC1Polarity: specifies the IC1 Polarity
*                    This parmeter can be one of the following values:
*                       - TIM1_ICPolarity_Falling
*                       - TIM1_ICPolarity_Rising
*                  - TIM1_IC2Polarity: specifies the IC2 Polarity
*                    This parmeter can be one of the following values:
*                       - TIM1_ICPolarity_Falling
*                       - TIM1_ICPolarity_Rising
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_EncoderInterfaceConfig(u16 TIM1_EncoderMode, u16 TIM1_IC1Polarity,
                                u16 TIM1_IC2Polarity)
{
  u32 tmpsmcr = 0;
  u32 tmpccmr1 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_ENCODER_MODE(TIM1_EncoderMode));
  assert_param(IS_TIM1_IC_POLARITY(TIM1_IC1Polarity));
  assert_param(IS_TIM1_IC_POLARITY(TIM1_IC2Polarity));

  tmpsmcr = TIM1->SMCR;
  tmpccmr1 = TIM1->CCMR1;

  /* Set the encoder Mode */
  tmpsmcr &= SMCR_SMS_Mask;
  tmpsmcr |= TIM1_EncoderMode;

  /* Select the Capture Compare 1 and the Capture Compare 2 as input */
  tmpccmr1 &= CCMR_CC13S_Mask & CCMR_CC24S_Mask;
  tmpccmr1 |= CCMR_TI13Direct_Set | CCMR_TI24Direct_Set;

  /* Set the TI1 and the TI2 Polarities */
  *(vu32 *) CCER_CC1P_BB = TIM1_IC1Polarity;
  *(vu32 *) CCER_CC2P_BB = TIM1_IC2Polarity;

  TIM1->SMCR = (u16)tmpsmcr;

  TIM1->CCMR1 = (u16)tmpccmr1;
}

/*******************************************************************************
* Function Name  : TIM1_PrescalerConfig
* Description    : Configures the TIM1 Prescaler.
* Input          : - Prescaler: specifies the Prescaler Register value
*                  - TIM1_PSCReloadMode: specifies the TIM1 Prescaler Reload mode.
*                    This parmeter can be one of the following values:
*                       - TIM1_PSCReloadMode_Update: The Prescaler is loaded at
*                         the update event.
*                       - TIM1_PSCReloadMode_Immediate: The Prescaler is loaded
*                         immediatly.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_PrescalerConfig(u16 Prescaler, u16 TIM1_PSCReloadMode)
{
  /* Check the parameters */
  assert_param(IS_TIM1_PRESCALER_RELOAD(TIM1_PSCReloadMode));

  /* Set the Prescaler value */
  TIM1->PSC = Prescaler;

  /* Set or reset the UG Bit */
  *(vu32 *) EGR_UG_BB = TIM1_PSCReloadMode;
}
/*******************************************************************************
* Function Name  : TIM1_CounterModeConfig
* Description    : Specifies the TIM1 Counter Mode to be used.
* Input          : - TIM1_CounterMode: specifies the Counter Mode to be used
*                    This parameter can be one of the following values:
*                       - TIM1_CounterMode_Up: TIM1 Up Counting Mode
*                       - TIM1_CounterMode_Down: TIM1 Down Counting Mode
*                       - TIM1_CounterMode_CenterAligned1: TIM1 Center Aligned Mode1
*                       - TIM1_CounterMode_CenterAligned2: TIM1 Center Aligned Mode2
*                       - TIM1_CounterMode_CenterAligned3: TIM1 Center Aligned Mode3
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_CounterModeConfig(u16 TIM1_CounterMode)
{
  u32 tmpcr1 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_COUNTER_MODE(TIM1_CounterMode));

  tmpcr1 = TIM1->CR1;

  /* Reset the CMS and DIR Bits */
  tmpcr1 &= CR1_CounterMode_Mask;

  /* Set the Counter Mode */
  tmpcr1 |= TIM1_CounterMode;

  TIM1->CR1 = (u16)tmpcr1;
}

/*******************************************************************************
* Function Name  : TIM1_ForcedOC1Config
* Description    : Forces the TIM1 Channel1 output waveform to active or inactive 
*                  level.
* Input          : - TIM1_ForcedAction: specifies the forced Action to be set to
*                    the output waveform.
*                    This parameter can be one of the following values:
*                       - TIM1_ForcedAction_Active: Force active level on OC1REF
*                       - TIM1_ForcedAction_InActive: Force inactive level on
*                         OC1REF.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_ForcedOC1Config(u16 TIM1_ForcedAction)
{
  u32 tmpccmr1 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_FORCED_ACTION(TIM1_ForcedAction));

  tmpccmr1 = TIM1->CCMR1;

  /* Reset the OCM Bits */
  tmpccmr1 &= CCMR_OCM13_Mask;

  /* Configure The Forced output Mode */
  tmpccmr1 |= TIM1_ForcedAction;

  TIM1->CCMR1 = (u16)tmpccmr1;
}

/*******************************************************************************
* Function Name  : TIM1_ForcedOC2Config
* Description    : Forces the TIM1 Channel2 output waveform to active or inactive 
*                  level.
* Input          : - TIM1_ForcedAction: specifies the forced Action to be set to
*                    the output waveform.
*                    This parameter can be one of the following values:
*                       - TIM1_ForcedAction_Active: Force active level on OC2REF
*                       - TIM1_ForcedAction_InActive: Force inactive level on
*                         OC2REF.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_ForcedOC2Config(u16 TIM1_ForcedAction)
{
  u32 tmpccmr1 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_FORCED_ACTION(TIM1_ForcedAction));

  tmpccmr1 = TIM1->CCMR1;

  /* Reset the OCM Bits */
  tmpccmr1 &= CCMR_OCM24_Mask;

  /* Configure The Forced output Mode */
  tmpccmr1 |= (u32)TIM1_ForcedAction << 8;

  TIM1->CCMR1 = (u16)tmpccmr1;
}

/*******************************************************************************
* Function Name  : TIM1_ForcedOC3Config
* Description    : Forces the TIM1 Channel3 output waveform to active or inactive 
*                  level.
* Input          : - TIM1_ForcedAction: specifies the forced Action to be set to
*                    the output waveform.
*                    This parameter can be one of the following values:
*                       - TIM1_ForcedAction_Active: Force active level on OC3REF
*                       - TIM1_ForcedAction_InActive: Force inactive level on
*                         OC3REF.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_ForcedOC3Config(u16 TIM1_ForcedAction)
{
  u32 tmpccmr2 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_FORCED_ACTION(TIM1_ForcedAction));

  tmpccmr2 = TIM1->CCMR2;

  /* Reset the OCM Bits */
  tmpccmr2 &= CCMR_OCM13_Mask;

  /* Configure The Forced output Mode */
  tmpccmr2 |= TIM1_ForcedAction;

  TIM1->CCMR2 = (u16)tmpccmr2;
}

/*******************************************************************************
* Function Name  : TIM1_ForcedOC4Config
* Description    : Forces the TIM1 Channel4 output waveform to active or inactive 
*                  level.
* Input          : - TIM1_ForcedAction: specifies the forced Action to be set to
*                    the output waveform.
*                    This parameter can be one of the following values:
*                       - TIM1_ForcedAction_Active: Force active level on OC4REF
*                       - TIM1_ForcedAction_InActive: Force inactive level on
*                         OC4REF.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_ForcedOC4Config(u16 TIM1_ForcedAction)
{
  u32 tmpccmr2 = 0;

  /* Check the parameters */
  assert_param(IS_TIM1_FORCED_ACTION(TIM1_ForcedAction));

  tmpccmr2 = TIM1->CCMR1;

  /* Reset the OCM Bits */
  tmpccmr2 &= CCMR_OCM24_Mask;

  /* Configure The Forced output Mode */
  tmpccmr2 |= (u16)((u16)TIM1_ForcedAction << 8);

  TIM1->CCMR2 = (u16)tmpccmr2;
}

/*******************************************************************************
* Function Name  : TIM1_ARRPreloadConfig
* Description    : Enables or disables TIM1 peripheral Preload register on ARR.
* Input          : - Newstate: new state of the TIM1 peripheral Preload register
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_ARRPreloadConfig(FunctionalState Newstate)
{
  /* Check the parameters */
  assert_param(IS_FUNCTIONAL_STATE(Newstate));

  /* Set or Reset the ARPE Bit */
  *(vu32 *) CR1_ARPE_BB = (u16)Newstate;
}

/*******************************************************************************
* Function Name  : TIM1_SelectCOM
* Description    : Selects the TIM1 peripheral Commutation event.
* Input          : - Newstate: new state of the Commutation event.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void TIM1_SelectCOM(FunctionalState Newstate)
{
  /* Check the parameters */
  assert_param(IS_FUNCTIONAL_STATE(Newstate));

  /* Set or Reset the CCUS Bit */
  *(vu32 *) CR2_CCUS_BB = (u16)Newstate;
}

/*******************************************************************************
* Function Name  : TIM1_SelectCCDMA
* Description    : Selects the TIM1 peripheral Capture Compare DMA source.
* Input          : - Newstate: new state of the Capture Compare DMA source
*                    This parameter can be: ENABLE

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -