?? 75x_tim.c
字號:
* Return : The new state of TIM_IT(SET or RESET).
*******************************************************************************/
ITStatus TIM_GetITStatus(TIM_TypeDef* TIMx, u16 TIM_IT)
{
u16 TIM_IT_Check = 0;
/* Calculates the pending bits to be checked */
TIM_IT_Check = TIM_IT & TIM_IT_Clear_Mask;
if((TIMx->ISR & TIM_IT_Check) != RESET )
{
return SET;
}
else
{
return RESET;
}
}
/*******************************************************************************
* Function Name : TIM_ClearITPendingBit
* Description : Clears the TIM's interrupt pending bits.
* Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral.
* - TIM_IT: specifies the interrupt pending bit to clear.
* This parameter can be one of the following values:
* - TIM_IT_IC1: Input Capture 1 Interrupt
* - TIM_IT_OC1: Output Compare 1 Interrupt
* - TIM_IT_Update: Timer update Interrupt
* - TIM_IT_GlobalUpdate: Timer global update Interrupt
* - TIM_IT_IC2: Input Capture 2 Interrupt
* - TIM_IT_OC2: Output Compare 2 Interrupt
* Output : None
* Return : None
*******************************************************************************/
void TIM_ClearITPendingBit(TIM_TypeDef* TIMx, u16 TIM_IT)
{
u16 TIM_IT_Clear = 0;
/* Calculate the pending bits to be cleared */
TIM_IT_Clear = TIM_IT & TIM_IT_Clear_Mask;
/* Clear the pending bits */
TIMx->ISR &= ~TIM_IT_Clear;
}
/*******************************************************************************
* Function Name : OCM_ModuleConfig
* Description : Output Compare Module configuration
* Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
* - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
* contains the configuration information for the specified TIM
* peripheral.
* Output : None
* Return : None
*******************************************************************************/
static void OCM_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
{
u16 TIM_OCControl = 0x0000;
if(TIM_InitStruct->TIM_Mode == TIM_Mode_OCTiming)
{
TIM_OCControl = TIM_OCControl_OCTiming;
}
else
{
if((TIM_InitStruct->TIM_Mode == TIM_Mode_OCActive) ||
(TIM_InitStruct->TIM_Mode == TIM_Mode_OPM_Active))
{
TIM_OCControl = TIM_OCControl_OCActive;
}
else
{
if(TIM_InitStruct->TIM_Mode == TIM_Mode_OCInactive)
{
TIM_OCControl = TIM_OCControl_OCInactive;
}
else
{
if((TIM_InitStruct->TIM_Mode == TIM_Mode_OCToggle) ||
(TIM_InitStruct->TIM_Mode == TIM_Mode_OPM_Toggle))
{
TIM_OCControl = TIM_OCControl_OCToggle;
}
else
{
TIM_OCControl = TIM_OCControl_PWM;
}
}
}
}
if(TIM_InitStruct->TIM_Channel == TIM_Channel_1)
{
/* Configure Channel 1 on Output Compare mode */
TIMx->OMR1 &= TIM_OC1C_Mask;
TIMx->OMR1 |= TIM_OCControl|TIM_OC1_Enable;
TIMx->OMR1 |= TIM_PLD1_Set;
TIMx->OCR1 = TIM_InitStruct->TIM_Pulse1;
/* Set the OC1 wave polarity */
if(TIM_InitStruct->TIM_Polarity1 == TIM_Polarity1_Low)
{
TIMx->OMR1 |= TIM_OC1P_Set;
}
else
{
TIMx->OMR1 &= TIM_OC1P_Reset;
}
}
else
{
if(TIM_InitStruct->TIM_Channel == TIM_Channel_2)
{
/* Configure Channel 2 on Output Compare mode */
TIMx->OMR1 &= TIM_OC2C_Mask;
TIMx->OMR1 |= TIM_OCControl<<8|TIM_OC2_Enable;
TIMx->OMR1 |= TIM_PLD2_Set;
TIMx->OCR2 = TIM_InitStruct->TIM_Pulse2;
/* Set the OCB wave polarity */
if(TIM_InitStruct->TIM_Polarity2 == TIM_Polarity2_Low)
{
TIMx->OMR1 |= TIM_OC2P_Set;
}
else
{
TIMx->OMR1 &= TIM_OC2P_Reset;
}
}
/* Configure Channel 1 and Channel 2 on Output Compare mode */
else
{
TIMx->OMR1 &= TIM_OC1C_Mask & TIM_OC2C_Mask;
TIMx->OMR1 |= TIM_OCControl|(TIM_OCControl<<8)|TIM_OC1_Enable|TIM_OC2_Enable|
TIM_PLD1_Set|TIM_PLD2_Set;
TIMx->OCR1 = TIM_InitStruct->TIM_Pulse1;
TIMx->OCR2 = TIM_InitStruct->TIM_Pulse2;
/* Set the OC1 wave polarity */
if(TIM_InitStruct->TIM_Polarity1 == TIM_Polarity1_Low)
{
TIMx->OMR1 |= TIM_OC1P_Set;
}
else
{
TIMx->OMR1 &= TIM_OC1P_Reset;
}
/* Set the OC2 wave polarity */
if(TIM_InitStruct->TIM_Polarity2 == TIM_Polarity2_Low)
{
TIMx->OMR1 |= TIM_OC2P_Set;
}
else
{
TIMx->OMR1 &= TIM_OC2P_Reset;
}
}
}
}
/*******************************************************************************
* Function Name : ICAP_ModuleConfig
* Description : Input Capture Module configuration
* Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
* - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
* contains the configuration information for the specified TIM
* peripheral.
* Output : None
* Return : None
*******************************************************************************/
static void ICAP_ModuleConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
{
if(TIM_InitStruct->TIM_Mode == TIM_Mode_PWMI)
{ /* PWM input mode configuration */
TIMx->SCR |= TIM_TS_IC1_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
/* Channel 1 and channel 2 input selection */
if(TIM_InitStruct->TIM_PWMI_ICSelection == TIM_PWMI_ICSelection_TI1)
{
TIMx->IMCR &= TIM_IC1S_Reset;
TIMx->IMCR |= TIM_IC2S_Set;
}
else
{
TIMx->IMCR |= TIM_IC1S_Set;
TIMx->IMCR &= TIM_IC2S_Reset;
}
/* Channel polarity */
if(TIM_InitStruct->TIM_PWMI_ICPolarity == TIM_PWMI_ICPolarity_Rising)
{
TIMx->IMCR &= TIM_IC1P_Reset;
TIMx->IMCR |= TIM_IC2P_Set;
}
else
{
TIMx->IMCR |= TIM_IC1P_Set;
TIMx->IMCR &= TIM_IC2P_Reset;
}
/* Input capture Enable */
TIMx->IMCR |= TIM_IC1_Enable |TIM_IC2_Enable;
}
else
{
if(TIM_InitStruct->TIM_Channel == TIM_Channel_1)
{
/* Input Capture 1 mode configuration */
TIMx->SCR &= TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask;
TIMx->SCR |= TIM_TS_IC1_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
/* Channel 1 input selection */
if(TIM_InitStruct->TIM_IC1Selection == TIM_IC1Selection_TI1)
{
TIMx->IMCR &= TIM_IC1S_Reset;
}
else
{
TIMx->IMCR |= TIM_IC1S_Set;
}
/* Channel 1 polarity */
if(TIM_InitStruct->TIM_IC1Polarity == TIM_IC1Polarity_Rising)
{
TIMx->IMCR &= TIM_IC1P_Reset;
}
else
{
TIMx->IMCR |= TIM_IC1P_Set;
}
/* Input capture Enable */
TIMx->IMCR |= TIM_IC1_Enable;
}
else
{
/* Input Capture 2 mode configuration */
TIMx->SCR &= (TIM_TriggerSelection_Mask & TIM_SlaveModeSelection_Mask);
TIMx->SCR |= TIM_TS_IC2_Set|TIM_SMS_RESETCLK_Set|TIM_SME_Set;
/* Channel 2 input selection */
if(TIM_InitStruct->TIM_IC2Selection == TIM_IC2Selection_TI2)
{
TIMx->IMCR &= TIM_IC2S_Reset;
}
else
{
TIMx->IMCR |= TIM_IC2S_Set;
}
/* Channel 2 polarity */
if(TIM_InitStruct->TIM_IC2Polarity == TIM_IC2Polarity_Rising)
{
TIMx->IMCR &= TIM_IC2P_Reset;
}
else
{
TIMx->IMCR |= TIM_IC2P_Set;
}
/* Input capture Enable */
TIMx->IMCR |= TIM_IC2_Enable;
}
}
}
/*******************************************************************************
* Function Name : Encoder_ModeConfig
* Description : Encoder Mode configuration
* Input : - TIMx: where x can be 0, 1 or 2 to select the TIM peripheral
* - TIM_InitStruct: pointer to a TIM_InitTypeDef structure that
* contains the configuration information for the specified TIM
* peripheral.
* Output : None
* Return : None
*******************************************************************************/
static void Encoder_ModeConfig(TIM_TypeDef* TIMx, TIM_InitTypeDef* TIM_InitStruct)
{
/* Set Encoder mode */
TIMx->SCR &= TIM_Encoder_Mask;
if(TIM_InitStruct->TIM_Mode == TIM_Mode_Encoder1)
{
TIMx->SCR |= TIM_Encoder1_Set;
}
else if (TIM_InitStruct->TIM_Mode == TIM_Mode_Encoder2)
{
TIMx->SCR |= TIM_Encoder2_Set;
}
else
{
TIMx->SCR |= TIM_Encoder3_Set;
}
/* Channel 1 input selection */
if(TIM_InitStruct->TIM_IC1Selection == TIM_IC1Selection_TI2)
{
TIMx->IMCR |= TIM_IC1S_Set;
}
else
{
TIMx->IMCR &= TIM_IC1S_Reset;
}
/* Channel 2 input selection */
if(TIM_InitStruct->TIM_IC2Selection == TIM_IC2Selection_TI1)
{
TIMx->IMCR |= TIM_IC2S_Set;
}
else
{
TIMx->IMCR &= TIM_IC2S_Reset;
}
/* Channel 1 polarity */
if(TIM_InitStruct->TIM_IC1Polarity == TIM_IC1Polarity_Falling)
{
TIMx->IMCR |= TIM_IC1P_Set;
}
else
{
TIMx->IMCR &= TIM_IC1P_Reset;
}
/* Channel 2 polarity */
if(TIM_InitStruct->TIM_IC2Polarity == TIM_IC2Polarity_Falling)
{
TIMx->IMCR |= TIM_IC2P_Set;
}
else
{
TIMx->IMCR &= TIM_IC2P_Reset;
}
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -