📄 stm8s_tim1.c
字号:
*/
void TIM1_ForcedOC3Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction)
{
/* Check the parameters */
assert_param(IS_TIM1_FORCED_ACTION_OK(TIM1_ForcedAction));
/* Reset the OCM Bits */ /* Configure The Forced output Mode */
TIM1->CCMR3 = (u8)((TIM1->CCMR3 & (u8)(~TIM1_CCMR_OCM)) | (u8)TIM1_ForcedAction);
}
/**
* @brief Forces the TIM1 Channel4 output waveform to active or inactive level.
* @param[in] 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.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_ForcedOC4Config(TIM1_ForcedAction_TypeDef TIM1_ForcedAction)
{
/* Check the parameters */
assert_param(IS_TIM1_FORCED_ACTION_OK(TIM1_ForcedAction));
/* Reset the OCM Bits & Configure the Forced output Mode */
TIM1->CCMR4 = (u8)((TIM1->CCMR4 & (u8)(~TIM1_CCMR_OCM)) | (u8)TIM1_ForcedAction);
}
/**
* @brief Enables or disables TIM1 peripheral Preload register on ARR.
* @param[in] NewState new state of the TIM1 peripheral Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_ARRPreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the ARPE Bit */
if (NewState != DISABLE)
{
TIM1->CR1 |= TIM1_CR1_ARPE;
}
else
{
TIM1->CR1 &= (u8)(~TIM1_CR1_ARPE);
}
}
/**
* @brief Selects the TIM1 peripheral Commutation event.
* @param[in] NewState new state of the Commutation event.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_SelectCOM(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the COMS Bit */
if (NewState != DISABLE)
{
TIM1->CR2 |= TIM1_CR2_COMS;
}
else
{
TIM1->CR2 &= (u8)(~TIM1_CR2_COMS);
}
}
/**
* @brief Sets or Resets the TIM1 peripheral Capture Compare Preload Control bit.
* @param[in] NewState new state of the Capture Compare Preload Control bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_CCPreloadControl(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the CCPC Bit */
if (NewState != DISABLE)
{
TIM1->CR2 |= TIM1_CR2_CCPC;
}
else
{
TIM1->CR2 &= (u8)(~TIM1_CR2_CCPC);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR1.
* @param[in] NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC1PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC1PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR1 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR1 &= (u8)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR2.
* @param[in] NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC2PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC2PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR2 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR2 &= (u8)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR3.
* @param[in] NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC3PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC3PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR3 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR3 &= (u8)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR4.
* @param[in] NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC4PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC4PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR4 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR4 &= (u8)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 1 Fast feature.
* @param[in] NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC1FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC1FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR1 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR1 &= (u8)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 2 Fast feature.
* @param[in] NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC2FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC2FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR2 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR2 &= (u8)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 3 Fast feature.
* @param[in] NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC3FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC3FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR3 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR3 &= (u8)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 4 Fast feature.
* @param[in] NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC4FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONALSTATE_OK(NewState));
/* Set or Reset the OC4FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR4 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR4 &= (u8)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 event to be generated by software.
* @param[in] TIM1_EventSource specifies the event source.
* This parameter can be one of the following values:
* - TIM1_EVENTSOURCE_UPDATE: TIM1 update Event source
* - TIM1_EVENTSOURCE_CC1: TIM1 Capture Compare 1 Event source
* - TIM1_EVENTSOURCE_CC2: TIM1 Capture Compare 2 Event source
* - TIM1_EVENTSOURCE_CC3: TIM1 Capture Compare 3 Event source
* - TIM1_EVENTSOURCE_CC4: TIM1 Capture Compare 4 Event source
* - TIM1_EVENTSOURCE_COM: TIM1 COM Event source
* - TIM1_EVENTSOURCE_TRIGGER: TIM1 Trigger Event source
* - TIM1_EventSourceBreak: TIM1 Break Event source
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_GenerateEvent(TIM1_EventSource_TypeDef TIM1_EventSource)
{
/* Check the parameters */
assert_param(IS_TIM1_EVENT_SOURCE_OK(TIM1_EventSource));
/* Set the event sources */
TIM1->EGR = (u8)TIM1_EventSource;
}
/**
* @brief Configures the TIM1 Channel 1 polarity.
* @param[in] TIM1_OCPolarity specifies the OC1 Polarity.
* This parameter can be one of the following values:
* - TIM1_OCPOLARITY_LOW: Output Compare active low
* - TIM1_OCPOLARITY_HIGH: Output Compare active high
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC1PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OC_POLARITY_OK(TIM1_OCPolarity));
/* Set or Reset the CC1P Bit */
if (TIM1_OCPolarity != TIM1_OCPOLARITY_HIGH)
{
TIM1->CCER1 |= TIM1_CCER1_CC1P;
}
else
{
TIM1->CCER1 &= (u8)(~TIM1_CCER1_CC1P);
}
}
/**
* @brief Configures the TIM1 Channel 1N polarity.
* @param[in] TIM1_OCNPolarity specifies the OC1N Polarity.
* This parameter can be one of the following values:
* - TIM1_OCNPOLARITY_LOW: Output Compare active low
* - TIM1_OCNPOLARITY_HIGH: Output Compare active high
* @retval None
* @par Required preconditions:
* None
*/
void TIM1_OC1NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OCN_POLARITY_OK(TIM1_OCNPolarity));
/* Set or Reset the CC3P Bit */
if (TIM1_OCNPolarity != TIM1_OCNPOLARITY_HIGH)
{
TIM1->CCER1 |= TIM1_CCER1_CC1NP;
}
else
{
TIM1->CCER1 &= (u8)(~TIM1_CCER1_CC1NP);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -