📄 91x_adc.c
字号:
{
return RESET;
}
}
else if(AdcReg == 0xC) /* The flag to check is in DR6 register */
{
if((ADC->DR6 & (1<<FlagPos))!= RESET)
{
return SET;
}
else
{
return RESET;
}
}
else /* (AdcReg == 0xD), The flag to check is in DR7 register */
{
if((ADC->DR7 & (1<<FlagPos))!= RESET)
{
return SET;
}
else
{
return RESET;
}
}
}
/*******************************************************************************
* Function Name : ADC_ClearFlag
* Description : Clears the ADC Flag passed as a parameter.
* Input : ADC_Flag: flag to clear.
* This parameter can be one of the following values:
* - ADC_FLAG_ECV: End of conversion status.
* - ADC_FLAG_AWD: Analog watchdog status.
* Output : None
* Return : None
*******************************************************************************/
void ADC_ClearFlag(u16 ADC_Flag)
{
/* Clear the correspondent flag */
ADC->CR |= (1<<(ADC_Flag & ADC_FLAG_MASK));
}
/*******************************************************************************
* Function Name : ADC_GetConversionValue
* Description : Read the result of conversion from the appropriate data
* register.
* Input : ADC_Channel: the correspondent channel of the ADC peripheral.
* This parameter can be one of the following values:
* - ADC_Channel_0: ADC channel 0.
* - ADC_Channel_1: ADC channel 1.
* - ADC_Channel_2: ADC channel 2.
* - ADC_Channel_3: ADC channel 3.
* - ADC_Channel_4: ADC channel 4.
* - ADC_Channel_5: ADC channel 5.
* - ADC_Channel_6: ADC channel 6.
* - ADC_Channel_7: ADC channel 7.
* Output : None
* Return : The result of the conversion for the specific channel.
*******************************************************************************/
u16 ADC_GetConversionValue(u16 ADC_Channel)
{
u16 ADC_Conversion_Value = 0;
switch (ADC_Channel)
{
case (ADC_Channel_0):
/* Get the conversion value of the channel 0 */
ADC_Conversion_Value = ADC->DR0 & ADC_RESULT_MASK;
break;
case (ADC_Channel_1):
/* Get the conversion value of the channel 1 */
ADC_Conversion_Value = ADC->DR1 & ADC_RESULT_MASK;
break;
case (ADC_Channel_2):
/* Get the conversion value of the channel 2 */
ADC_Conversion_Value = ADC->DR2 & ADC_RESULT_MASK;
break;
case (ADC_Channel_3):
/* Get the conversion value of the channel 3 */
ADC_Conversion_Value = ADC->DR3 & ADC_RESULT_MASK;
break;
case (ADC_Channel_4):
/* Get the conversion value of the channel 4 */
ADC_Conversion_Value = ADC->DR4 & ADC_RESULT_MASK;
break;
case (ADC_Channel_5):
/* Get the conversion value of the channel 5 */
ADC_Conversion_Value = ADC->DR5 & ADC_RESULT_MASK;
break;
case (ADC_Channel_6):
/* Get the conversion value of the channel 6 */
ADC_Conversion_Value = ADC->DR6 & ADC_RESULT_MASK;
break;
case (ADC_Channel_7):
/* Get the conversion value of the channel 7 */
ADC_Conversion_Value = ADC->DR7 & ADC_RESULT_MASK;
break;
default:
break;
}
return(ADC_Conversion_Value);
}
/*******************************************************************************
* Function Name : ADC_GetAnalogWatchdogResult
* Description : Return the result of the comparaison on the selected Analog
* Watchdog.
* Input : ADC_Channel: the correspondent channel of the ADC peripheral.
* This parameter can be one of the following values:
* - ADC_Channel_0: ADC channel 0.
* - ADC_Channel_1: ADC channel 1.
* - ADC_Channel_2: ADC channel 2.
* - ADC_Channel_3: ADC channel 3.
* - ADC_Channel_4: ADC channel 4.
* - ADC_Channel_5: ADC channel 5.
* - ADC_Channel_6: ADC channel 6.
* - ADC_Channel_7: ADC channel 7.
* Output : None
* Return : The state of the comparision (SET or RESET).
*******************************************************************************/
FlagStatus ADC_GetAnalogWatchdogResult(u16 ADC_Channel)
{
if (ADC->CRR & (1<<ADC_Channel) != RESET)
{
return SET;
}
else
{
return RESET;
}
}
/*******************************************************************************
* Function Name : ADC_ClearAnalogWatchdogResult
* Description : Clear the result of the comparaison on the selected Analog
* Watchdog.
* Input : ADC_Channel: the correspondent channel of the ADC peripheral.
* This parameter can be one of the following values:
* - ADC_Channel_0: ADC channel 0.
* - ADC_Channel_1: ADC channel 1.
* - ADC_Channel_2: ADC channel 2.
* - ADC_Channel_3: ADC channel 3.
* - ADC_Channel_4: ADC channel 4.
* - ADC_Channel_5: ADC channel 5.
* - ADC_Channel_6: ADC channel 6.
* - ADC_Channel_7: ADC channel 7.
* Output : None
* Return : None
*******************************************************************************/
void ADC_ClearAnalogWatchdogResult(u16 ADC_Channel)
{
/* Clear the correspondent watchdog result */
ADC->CRR = 1<<ADC_Channel;
}
/*******************************************************************************
* Function Name : ADC_GetWatchdogThreshold
* Description : Get the higher/lower thresholds values of the watchdog.
* Input : ADC_Threshold: the lower or the higher threshold.
* This parameter can be one of the following values:
* - ADC_HigherThreshold: The higher threshold.
* - ADC_LowerThreshold: The lower threshold.
* Output : None
* Return : The selected threshold value.
*******************************************************************************/
u16 ADC_GetWatchdogThreshold(ADC_ThresholdType ADC_Threshold)
{
u16 ADC_Threshold_Value = 0;
switch (ADC_Threshold)
{
case ADC_LowThreshold:
/* Get the low threshold of the watchdog */
ADC_Threshold_Value = ADC->LTR;
break;
case ADC_HighThreshold:
/* Get the high threshol of the watchdog */
ADC_Threshold_Value = ADC->HTR;
break;
default:
break;
}
return(ADC_Threshold_Value);
}
/*******************************************************************************
* Function Name : ADC_ITConfig
* Description : Enables or disables the specified ADC interrupts.
* Input : - ADC_IT: specifies the ADC interrupts sources to be enabled
* or disabled.
* This parameter can be one of the following values:
* - ADC_IT_EndOfConversion: End of conversion interrupt.
* - ADC_IT_AnalogWDG: Analog watchdog interrupt.
* - ADC_NewState: new state of the specified ADC interrupts.
* (ADC_Newstate can be ENABLE or DISABLE).
* Output : None
* Return : None
*******************************************************************************/
void ADC_ITConfig(u16 ADC_IT, FunctionalState ADC_NewState)
{
if (ADC_NewState == ENABLE)
{
/* Enable the interrupt */
ADC->CR |= ADC_IT;
}
else
{
/* Disable the interrupt */
ADC->CR &= ~ADC_IT;
}
}
/*******************************************************************************
* Function Name : ADC_StandbyModeCmd
* Description : Enable or disable the standby mode.
* Input : ADC_NewState: new state of the ADC standby mode.
* (ADC_Newstate can be ENABLE or DISABLE).
* Output : None
* Return : None
*******************************************************************************/
void ADC_StandbyModeCmd(FunctionalState ADC_NewState)
{
if (ADC_NewState == ENABLE)
{
/* Enable the standby mode */
ADC->CR |= ADC_STANDBY_MODE_MASK;
}
else
{
/* Disable the standby mode */
ADC->CR &= ~ADC_STANDBY_MODE_MASK;
}
}
/*******************************************************************************
* Function Name : ADC_Cmd
* Description : Power on or put in reset mode the ADC peripheral.
* Input : ADC_NewState: new state of the ADC peripheral.
* (ADC_Newstate can be ENABLE or DISABLE).
* Output : None
* Return : None
*******************************************************************************/
void ADC_Cmd(FunctionalState ADC_NewState)
{
if (ADC_NewState == ENABLE)
{
/* Enable the ADC */
ADC->CR |= ADC_CMD_MASK;
}
else
{
/* Disable the ADC */
ADC->CR &= ~ADC_CMD_MASK;
}
}
/*******************************************************************************
* Function Name : ADC_ConversionCmd
* Description : Start or stop the ADC conversion in the selected mode.
* Input : ADC_Conversion: the conversion command.
* This parameter can be one of the following values:
* - ADC_Conversion_Start: Start the conversion.
* - ADC_Conversion_Stop: Stop the Conversion.
* Output : None
* Return : None
*******************************************************************************/
void ADC_ConversionCmd(u16 ADC_Conversion)
{
if (ADC_Conversion == ADC_Conversion_Start)
{
/* Start the ADC conversion */
ADC->CR |= ADC_Conversion_Start;
}
else
{
/* Stop the ADC conversion */
ADC->CR &= ADC_Conversion_Stop;
}
}
/******************* (C) COPYRIGHT 2006 STMicroelectronics *****END OF FILE****/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -