⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 91x_adc.c

📁 STR912 arm9实现的以太网通信程序
💻 C
📖 第 1 页 / 共 2 页
字号:
*                  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_IT==ADC_IT_ORD) 
  {
   if (ADC_NewState == ENABLE)
  
    /* Enable the interrupt */
     ADC->CR2 |= ADC_IT;
 
  else

    /* Disable the interrupt */
    ADC->CR2 &= ~ADC_IT;
 
  }
  else{
  
   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;
  }
}
/*******************************************************************************
* Function Name  : ADC_ExternalTrigConfig
* Description    : source and edge selection of external trigg
* Input          : -ADC_ExtTrig_Src
*                  This parameter can be one of the following values:
*                     ADC_PWM_Trig    : PWM Trigger 
*                     ADC_TIM_Trig    : Timer Trigger 
*                     ADC_PIN_Trig    : External Trigger Pin 
*                
*                  -ADC_ExtTrig_Edge
*                   This parameter can be one of the following values:
*                   Falling_ETE        :Falling edge
*                   Rising_ETE         :Rising edge
* Output         : None
* Return         : None
*******************************************************************************/

void ADC_ExternalTrigConfig(u16 ADC_ExtTrig_Src ,  u16 ADC_ExtTrig_Edge)
  {
   ADC->CR2 &= 0x3C;
   ADC->CR2 |= ADC_ExtTrig_Src;

   if (ADC_ExtTrig_Edge== Falling_ETE)
   ADC->CR2 |= 0x20;
   else
   ADC->CR2 &=~0x20; ;
  
  }
/*******************************************************************************
* Function Name  :  ADC_ExternalTrigCmd
* Description    : Enable or disable the external trigg feature.
* Input          : ADC_NewState:  Can be ENABLE or DISABLE
* Output         : None
* Return         : None
*******************************************************************************/

void ADC_ExternalTrigCmd(FunctionalState ADC_NewState)
{
if (ADC_NewState==ENABLE)
  ADC->CR2 |= 0x04;                    
  else
  ADC->CR2  &=~0x04;  

}
/*******************************************************************************
* Function Name  : ADC_DMACmd
* Description    : Enable or disable the DMA request for ADC
* Input          : ADC_NewState:  Can be ENABLE or DISABLE
* Output         : None
* Return         : None
*******************************************************************************/
 
void ADC_DMACmd(FunctionalState ADC_NewState)
{
if (ADC_NewState==ENABLE)
  ADC->CR2 |= 0x08;                    
  else
  ADC->CR2  &=~0x08;  
}

/*******************************************************************************
* Function Name  : ADC_AutomaticClockGatedCmd
* Description    : Enables or disables the Automatic clock gated mode for Fast
*                  Trigger mode (only in Rev H).
* Input          : ADC_NewState:  Can be ENABLE or DISABLE
* Output         : None
* Return         : None
*******************************************************************************/
 
void ADC_AutomaticClockGatedCmd(FunctionalState ADC_NewState)
{
if (ADC_NewState==ENABLE)
  SCU->GPIOANA |= 0x100;                    
  else
  SCU->GPIOANA  &=~0x100;  
}


/******************* (C) COPYRIGHT 2007 STMicroelectronics *****END OF FILE****/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -