📄 75x_tb.c
字号:
}
/*******************************************************************************
* Function Name : TB_SetPrescaler
* Description : Sets the TB Prescaler value.
* Input : Prescaler: specifies the TB Prescaler value.
* Output : None
* Return : None
*******************************************************************************/
void TB_SetPrescaler(u16 Prescaler)
{
/* Sets the prescaler value */
TB->PSC = Prescaler;
}
/*******************************************************************************
* Function Name : TB_ResetCounter
* Description : Re-intializes the counter and generates an update of the
* registers.
* Input : None
* Output : None
* Return : None
*******************************************************************************/
void TB_ResetCounter(void)
{
/* Re-intializes TB counter */
TB->CR |= TB_COUNTER_Reset;
}
/*******************************************************************************
* Function Name : TB_DebugCmd
* Description : Enables or disables TB peripheral Debug control.
* Input : Newstate: new state of the TB Debug control.
* This parameter can be: ENABLE or DISABLE.
* Output : None
* Return : None
*******************************************************************************/
void TB_DebugCmd(FunctionalState Newstate)
{
if(Newstate == ENABLE)
{
TB->CR |= TB_DBGC_Set;
}
else
{
TB->CR &= TB_DBGC_Reset;
}
}
/*******************************************************************************
* Function Name : TB_CounterModeConfig
* Description : Configures the TB Counter Mode.
* Input : TB_CounterMode: specifies the TB counter mode to be used.
* This parameter can be one of the following values:
* - TB_CounterMode_Up: TB Up Counting Mode
* - TB_CounterMode_Down: TB Down Counting Mode
* - TB_CounterMode_CenterAligned: TB Center Aligned Mode
* Output : None
* Return : None
*******************************************************************************/
void TB_CounterModeConfig(u16 TB_CounterMode)
{
/* Counter mode configuration */
TB->CR &= TB_CounterMode_Mask;
TB->CR |= TB_CounterMode;
}
/*******************************************************************************
* Function Name : TB_SLaveModeConfig
* Description : Configures the TB slave Mode.
* Input : TB_SMSMode: specifies the TB slave mode to be used.
* This parameter can be one of the following values:
* - TB_SMSMode_Trigger: The counter starts at a rising
* edge of the trigger
* - TB_SMSMode_Gated: The counter clock is enabled when
* trigger signal is high
* - TB_SMSMode_External: The rising edge of selected trigger
* clocks the counter
* - TB_SMSMode_Reset: The rising edge of the selected
* trigger signal resets the counter
* Output : None
* Return : None
*******************************************************************************/
void TB_SLaveModeConfig(u16 TB_SMSMode)
{
TB->SCR &= TB_SME_Reset & TB_SlaveModeSelection_Mask & TB_TriggerSelection_Mask;
TB->SCR |= TB_SME_Set | TB_SMSMode | TB_TS_IC1_Set;
}
/*******************************************************************************
* Function Name : TB_GetCounter
* Description : Gets the TB Counter value.
* Input : None
* Output : None
* Return : The TB counter register value.
*******************************************************************************/
u16 TB_GetCounter(void)
{
return TB->CNT;
}
/*******************************************************************************
* Function Name : TB_GetICAP1
* Description : Gets the TB Input capture value.
* Input : None
* Output : None
* Return : The TB ICR1 register value.
*******************************************************************************/
u16 TB_GetICAP1(void)
{
return TB->ICR1;
}
/*******************************************************************************
* Function Name : TB_SetCounter
* Description : Sets the TB Counter value.
* Input : Counter: specifies the TB Counter value.
* Output : None
* Return : None
*******************************************************************************/
void TB_SetCounter(u16 Counter)
{
TB->CNT = Counter;
}
/*******************************************************************************
* Function Name : TB_GetFlagStatus
* Description : Checks whether the specified TB flag is set or not.
* Input : TB_FLAG: specifies the flag to check.
* This parameter can be one of the following values:
* - TB_FLAG_IC: TB Input Capture flag
* - TB_FLAG_Update: TB update flag
* Output : None
* Return : The new state of the TB_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus TB_GetFlagStatus(u16 TB_FLAG)
{
if((TB->ISR & TB_FLAG) != RESET )
{
return SET;
}
else
{
return RESET;
}
}
/*******************************************************************************
* Function Name : TB_ClearFlag
* Description : Clears the TB抯 pending flags.
* Input : TB_FLAG: specifies the flag to clear.
* This parameter can be any combination of the following values:
* - TB_FLAG_IC: TB Input Capture flag
* - TB_FLAG_Update: TB update flag
* Output : None
* Return : None
*******************************************************************************/
void TB_ClearFlag(u16 TB_FLAG)
{
/* Clears the flags */
TB->ISR &= ~TB_FLAG;
}
/*******************************************************************************
* Function Name : TB_GetITStatus
* Description : Checks whether the specified TB interrupt has occurred or not.
* Input : TB_IT: specifies the interrupt to check.
* This parameter can be one of the following values:
* - TB_IT_Update: TB Update interrupt
* - TB_IT_GlobalUpdate: TB Global Update interrupt
* - TB_IT_IC: TB Input Capture interrupt
* Output : None
* Return : The new state of the TB_IT (SET or RESET).
*******************************************************************************/
ITStatus TB_GetITStatus(u16 TB_IT)
{
u16 TB_IT_Check = 0;
/* Calculates the pending bits to be checked */
TB_IT_Check = TB_IT & TB_IT_Clear_Mask;
if((TB->ISR & TB_IT_Check) != RESET )
{
return SET;
}
else
{
return RESET;
}
}
/*******************************************************************************
* Function Name : TB_ClearITPendingBit
* Description : Clears the TB's interrupt pending bits.
* Input : TB_IT: specifies the interrupt pending bit to clear.
* This parameter can be any combination of the following values:
* - TB_IT_Update: TB Update interrupt
* - TB_IT_GlobalUpdate: TB Global Update interrupt
* - TB_IT_IC: TB Input Capture interrupt
* Output : None
* Return : None
*******************************************************************************/
void TB_ClearITPendingBit(u16 TB_IT)
{
u16 TB_IT_Clear = 0;
/* Calculates the pending bits to be cleared */
TB_IT_Clear = TB_IT & TB_IT_Clear_Mask;
/* Clears the pending bits */
TB->ISR &= ~TB_IT_Clear;
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -