stm8l15x_tim1.c
来自「STM8L的tim4定时器使用」· C语言 代码 · 共 1,720 行 · 第 1/5 页
C
1,720 行
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC1PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR1 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR1 &= (uint8_t)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR2.
* @param NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC2PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC2PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR2 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR2 &= (uint8_t)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR3.
* @param NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC3PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC3PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR3 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR3 &= (uint8_t)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Enables or disables the TIM1 peripheral Preload Register on CCR4.
* @param NewState new state of the Capture Compare Preload register.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC4PreloadConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC4PE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR4 |= TIM1_CCMR_OCxPE;
}
else
{
TIM1->CCMR4 &= (uint8_t)(~TIM1_CCMR_OCxPE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 1 Fast feature.
* @param NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC1FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC1FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR1 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR1 &= (uint8_t)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 2 Fast feature.
* @param NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC2FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC2FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR2 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR2 &= (uint8_t)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Configures the TIM1 Capture Compare 3 Fast feature.
* @param NewState new state of the Output Compare Fast Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_OC3FastConfig(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC3FE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR3 |= TIM1_CCMR_OCxFE;
}
else
{
TIM1->CCMR3 &= (uint8_t)(~TIM1_CCMR_OCxFE);
}
}
/**
* @brief Clears or safeguards the OC1REF signal.
* @param NewState new state of the Output Compare 1 Clear Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_ClearOC1Ref(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC1CE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR1 |= TIM1_CCMR_OCxCE;
}
else
{
TIM1->CCMR1 &= (uint8_t)(~TIM1_CCMR_OCxCE);
}
}
/**
* @brief Clears or safeguards the OC2REF signal.
* @param NewState new state of the Output Compare 2 Clear Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_ClearOC2Ref(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC2CE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR2 |= TIM1_CCMR_OCxCE;
}
else
{
TIM1->CCMR2 &= (uint8_t)(~TIM1_CCMR_OCxCE);
}
}
/**
* @brief Clears or safeguards the OC3REF signal.
* @param NewState new state of the Output Compare 3 Clear Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_ClearOC3Ref(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC3CE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR3 |= TIM1_CCMR_OCxCE;
}
else
{
TIM1->CCMR3 &= (uint8_t)(~TIM1_CCMR_OCxCE);
}
}
/**
* @brief Clears or safeguards the OC4REF signal.
* @param NewState new state of the Output Compare 4 Clear Enable bit.
* This parameter can be ENABLE or DISABLE.
* @retval None
*/
void TIM1_ClearOC4Ref(FunctionalState NewState)
{
/* Check the parameters */
assert_param(IS_FUNCTIONAL_STATE(NewState));
/* Set or Reset the OC4CE Bit */
if (NewState != DISABLE)
{
TIM1->CCMR4 |= TIM1_CCMR_OCxCE;
}
else
{
TIM1->CCMR4 &= (uint8_t)(~TIM1_CCMR_OCxCE);
}
}
/**
* @brief Configures the TIM1 Channel 1 polarity.
* @param TIM1_OCPolarity specifies the OC1 Polarity.
* This parameter can be one of the following values:
* @arg TIM1_OCPolarity_High: Output Compare active low
* @arg TIM1_OCPolarity_Low: Output Compare active high
* @retval None
*/
void TIM1_OC1PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OC_POLARITY(TIM1_OCPolarity));
/* Set or Reset the CC1P Bit */
if (TIM1_OCPolarity != TIM1_OCPolarity_High)
{
TIM1->CCER1 |= TIM1_CCER1_CC1P;
}
else
{
TIM1->CCER1 &= (uint8_t)(~TIM1_CCER1_CC1P);
}
}
/**
* @brief Configures the TIM1 Channel 1N polarity.
* @param TIM1_OCNPolarity specifies the OC1N Polarity.
* This parameter can be one of the following values:
* @arg TIM1_OCNPolarity_High: Complementary Output Compare active low
* @arg TIM1_OCNPolarity_Low: Complementary Output Compare active high
* @retval None
*/
void TIM1_OC1NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OCN_POLARITY(TIM1_OCNPolarity));
/* Set or Reset the CC3P Bit */
if (TIM1_OCNPolarity != TIM1_OCNPolarity_High)
{
TIM1->CCER1 |= TIM1_CCER1_CC1NP;
}
else
{
TIM1->CCER1 &= (uint8_t)(~TIM1_CCER1_CC1NP);
}
}
/**
* @brief Configures the TIM1 Channel 2 polarity.
* @param TIM1_OCPolarity specifies the OC2 Polarity.
* This parameter can be one of the following values:
* @arg TIM1_OCPolarity_High: Output Compare active low
* @arg TIM1_OCPolarity_Low: Output Compare active high
* @retval None
*/
void TIM1_OC2PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OC_POLARITY(TIM1_OCPolarity));
/* Set or Reset the CC2P Bit */
if (TIM1_OCPolarity != TIM1_OCPolarity_High)
{
TIM1->CCER1 |= TIM1_CCER1_CC2P;
}
else
{
TIM1->CCER1 &= (uint8_t)(~TIM1_CCER1_CC2P);
}
}
/**
* @brief Configures the TIM1 Channel 2N polarity.
* @param TIM1_OCNPolarity specifies the OC2N Polarity.
* This parameter can be one of the following values:
* @arg TIM1_OCNPolarity_High: Complementary Output Compare active low
* @arg TIM1_OCNPolarity_Low: Complementary Output Compare active high
* @retval None
*/
void TIM1_OC2NPolarityConfig(TIM1_OCNPolarity_TypeDef TIM1_OCNPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OCN_POLARITY(TIM1_OCNPolarity));
/* Set or Reset the CC3P Bit */
if (TIM1_OCNPolarity != TIM1_OCNPolarity_High)
{
TIM1->CCER1 |= TIM1_CCER1_CC2NP;
}
else
{
TIM1->CCER1 &= (uint8_t)(~TIM1_CCER1_CC2NP);
}
}
/**
* @brief Configures the TIM1 Channel 3 polarity.
* @param TIM1_OCPolarity specifies the OC3 Polarity.
* This parameter can be one of the following values:
* @arg TIM1_OCPolarity_High: Output Compare active low
* @arg TIM1_OCPolarity_Low: Output Compare active high
* @retval None
*/
void TIM1_OC3PolarityConfig(TIM1_OCPolarity_TypeDef TIM1_OCPolarity)
{
/* Check the parameters */
assert_param(IS_TIM1_OC_POLARITY(TIM1_OCPolarity));
/* Set or Reset the CC3P Bit */
if (TIM1_OCPolarity != TIM1_OCPolarity_High)
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?