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

📄 73x_adc.c

📁 国外LPC2000系列的一些源程序,请大家快快下载
💻 C
📖 第 1 页 / 共 2 页
字号:
      ADC->TRA0 = (ADC->TRA0 & 0xFC00) |  HighThreshold;
      ADC->TRB0 = (ADC->TRB0 & 0xFC00) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog1 :
      ADC->TRA1 = (ADC->TRA1 & 0xC3FF) | ((u16) ADC_Channel<<10);
      ADC->TRA1 = (ADC->TRA1 & 0xFC00) |  HighThreshold;
      ADC->TRB1 = (ADC->TRB1 & 0xFC00) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog2 :
      ADC->TRA2 = (ADC->TRA2 & 0xC3FF) | ((u16) ADC_Channel<<10);
      ADC->TRA2 = (ADC->TRA2 & 0xFC00) |  HighThreshold;
      ADC->TRB2 = (ADC->TRB2 & 0xFC00) |  LowThreshold;
      break;

    case ADC_AnalogWatchdog3 :
      ADC->TRA3 = (ADC->TRA3 & 0xC3FF) | ((u16) ADC_Channel<<10);
      ADC->TRA3 = (ADC->TRA3 & 0xFC00) |  HighThreshold;
      ADC->TRB3 = (ADC->TRB3 & 0xFC00) |  LowThreshold;
      break;
  }
}

/*******************************************************************************
* Function Name  : ADC_AnalogWatchdogCmd                                   
* Description    : Enable/Disable the selected analog Watchdog                      
* Input          : - ADC_Watchdog: the selected analog watchdog. This parameter can be 
*                    one of the following values: 
*                         - ADC_Watchdog0: select analog watchdog 0                       
*		          - ADC_Watchdog1: select analog watchdog 1                       
*         	          - ADC_Watchdog2: select analog watchdog 2                       
*                         - ADC_Watchdog3: select analog watchdog 3                                       
*                  - NewState: new state of the specified analog watchdog.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None.                                                   
********************************************************************************/
void ADC_AnalogWatchdogCmd(u16 ADC_Watchdog, FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    /* Enable ADC Thresholds */
    switch (ADC_Watchdog)
    {
      case ADC_AnalogWatchdog0 : ADC->TRB0 |= ADC_AnalogWatchdog_Enable;  break;
      case ADC_AnalogWatchdog1 : ADC->TRB1 |= ADC_AnalogWatchdog_Enable;  break;
      case ADC_AnalogWatchdog2 : ADC->TRB2 |= ADC_AnalogWatchdog_Enable;  break;
      case ADC_AnalogWatchdog3 : ADC->TRB3 |= ADC_AnalogWatchdog_Enable;  break;
    }
  }
  else
  {
    /* Disable ADC Thresholds */
    switch (ADC_Watchdog)
    {
      case ADC_AnalogWatchdog0 : ADC->TRB0 &= ADC_AnalogWatchdog_Disable;  break;
      case ADC_AnalogWatchdog1 : ADC->TRB1 &= ADC_AnalogWatchdog_Disable;  break;
      case ADC_AnalogWatchdog2 : ADC->TRB2 &= ADC_AnalogWatchdog_Disable;  break;
      case ADC_AnalogWatchdog3 : ADC->TRB3 &= ADC_AnalogWatchdog_Disable;  break;
    }
  }
}

/*******************************************************************************
* Function Name  : ADC_GetAnalogWatchdogResult                               
* Description    : Return the analog watchdog comparaison result          
* Input          : - ADC_Watchdog: the selected analog watchdog. This parameter can be 
*                    one of the following values: 
*                         - ADC_Watchdog0: select analog watchdog 0                       
*		          - ADC_Watchdog1: select analog watchdog 1                       
*         	          - ADC_Watchdog2: select analog watchdog 2                       
*                         - ADC_Watchdog3: select analog watchdog 3                                       
* Output         : None              
* Return         : The analog watchdog comparaison result value                 
********************************************************************************/
u16 ADC_GetAnalogWatchdogResult (u16 ADC_Watchdog)
{
  /* Return the AnalogWatchdog comparaison result */
  switch(ADC_Watchdog)
  {
    case ADC_AnalogWatchdog0 :
      return ((ADC->PBR & ADC_Watchdog)>>4);

    case ADC_AnalogWatchdog1 :
      return ((ADC->PBR & ADC_Watchdog)>>6);

    case ADC_AnalogWatchdog2 :
      return ((ADC->PBR & ADC_Watchdog)>>8);

    case ADC_AnalogWatchdog3 :
      return ((ADC->PBR & ADC_Watchdog)>>10);

    default : return (0xFF);  /* if a wrong value of ADC_Watchdog is selected */
  }
}

/*******************************************************************************
* Function Name  : ADC_InjectedConversionStart
* Description    : Start the Injected Conversion.
* Input          : None
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_InjectedConversionStart (void)
{
  /* Start the injected ADC Conversion */
  ADC->CLR3 |= ADC_Injec_ConversionStart;
}

/*******************************************************************************
* Function Name  : ADC_InjectedChannelsSelect
* Description    : Select injected channels passed as parameter to be converted.
* Input          : - FirstChannel: first converted channel. This parameter can be 
*                     ADC_CHANNELx where x can be (0..15). 
*                  - ChannelNumber: number of converted channels. This parameter 
*                     can be a value from 1 to 16.    
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_InjectedChannelsSelect(u8 FirstChannel,u8 ChannelNumber)
{
  /* Set the First channel to convert */
  ADC->CLR3 = (ADC->CLR3 & 0xFFF0) | FirstChannel;
  /* Set the Last channel to convert */
  ADC->CLR3 = (ADC->CLR3 & 0xFC3F) | (ChannelNumber-1<<6);
}

/*******************************************************************************
* Function Name  : ADC_GetConversionValue
* Description    : Read the conversion result from the data register.
* Input          : - ADC_Channel :ADC channel register value to beread.
*                    This parameter can be ADC_CHANNELx where x can 
*                    be (0..15) to select channelx  
* Output         : None
* Return         : The register value of the converted channel 
*******************************************************************************/
u16 ADC_GetConversionValue( u16 ADC_Channel)
{
  return *((u16 *)(ADC_BASE + ((ADC_Channel<<2) +0x0050)));
}

/*******************************************************************************
* 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 any combination of the
*                    following values:
*                         - ADC_IT_ECH:  End of chain conversion interrupt mask
*                         - ADC_IT_EOC:  End of channel conversion interrupt mask
*                         - ADC_IT_JECH: End of injected chain conversion interrupt mask
*                         - ADC_IT_JEOC: End of injected channel conversion interrupt mask
*                         - ADC_IT_AnalogWatchdog0_LowThresold:  Analog Watchdog0 LowThresold interrupt mask       
*                         - ADC_IT_AnalogWatchdog0_HighThresold: Analog Watchdog0 HighThresold interrupt mask 	
*                         - ADC_IT_AnalogWatchdog1_LowThresold:  Analog Watchdog1 LowThresold interrupt mask  	
*                         - ADC_IT_AnalogWatchdog1_HighThresold: Analog Watchdog1 HighThresold interrupt mask  	
*                         - ADC_IT_AnalogWatchdog2_LowThresold:  Analog Watchdog2 LowThresold interrupt mask  	
*                         - ADC_IT_AnalogWatchdog2_HighThresold: Analog Watchdog2 HighThresold interrupt mask 	
*                         - ADC_IT_AnalogWatchdog3_LowThresold:  Analog Watchdog3 LowThresold interrupt mask  	
*                         - ADC_IT_AnalogWatchdog3_HighThresold: Analog Watchdog3 HighThresold interrupt mask 	
*                  - NewState: new state of the specified ADC interrupts.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_ITConfig(u16 ADC_IT, FunctionalState NewState )
{
  if (NewState == ENABLE)
  {
    ADC->IMR |= ADC_IT;
  }
  else
  {
    ADC->IMR &= ~ADC_IT;
  }
}

/*******************************************************************************
* Function Name  : ADC_FlagClear
* Description    : Clear the ADC flags passed as parameters 
* Input          : - ADC_Flag: flag to clear. This parameter can be can be any 
*                    combination of the following values:
*                         - ADC_FLAG_ECH:  End of chain conversion
*                         - ADC_FLAG_EOC:  End of channel conversion
*                         - ADC_FLAG_JECH: End of injected chain conversion
*                         - ADC_FLAG_JEOC: End of injected channel conversion
*                         - ADC_FLAG_AnalogWatchdog0_LowThresold:  Analog Watchdog 0 LowThresold Flag        
*                         - ADC_FLAG_AnalogWatchdog0_HighThresold: Analog Watchdog 0 HighThresold Flag 	
*                         - ADC_FLAG_AnalogWatchdog1_LowThresold:  Analog Watchdog 1 LowThresold Flag  	
*                         - ADC_FLAG_AnalogWatchdog1_HighThresold: Analog Watchdog 1 HighThresold Flag  	
*                         - ADC_FLAG_AnalogWatchdog2_LowThresold:  Analog Watchdog 2 LowThresold Flag  	
*                         - ADC_FLAG_AnalogWatchdog2_HighThresold: Analog Watchdog 2 HighThresold Flag 	
*                         - ADC_FLAG_AnalogWatchdog3_LowThresold:  Analog Watchdog 3 LowThresold Flag  	
*                         - ADC_FLAG_AnalogWatchdog3_HighThresold: Analog Watchdog 3 HighThresold Flag 	
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_FlagClear (u16 ADC_Flag)
{
  /* Clear flags by setting their corresponding bits in PBR register */
  ADC->PBR = ADC_Flag;
}

/*******************************************************************************
* Function Name  : ADC_FlagStatus
* Description    : Checks whether the specified ADC flag is set or not.
* Input          : - ADC_Flag: flag to check. This parameter can be one of the
*                    following values:
*                         - ADC_FLAG_ECHECH :End of chain conversion
*                         - ADC_FLAG_EOC :End of channel conversion
*                         - ADC_FLAG_JECH :End of injected chain conversion
*                         - ADC_FLAG_JEOC :End of injected channel conversion 
* Output         : None	
* Return         : The NewState of the ADC_Flag (SET or RESET).
*******************************************************************************/
FlagStatus ADC_FlagStatus (u8 ADC_Flag)
{
  /* Test on the flag status and return set or RESET */
  if(ADC->PBR & ADC_Flag)
  {
    return SET;
  }
  else
  {
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : ADC_DMAConfig
* Description    : Enables or disables the ADC channels for DMA transfert.
* Input          : - ADC_DMAChannel: channels selected to be enabled or disabled 
*                    for DMA transfert. This parameter can be any combination of 
*                    ADC_DMA_CHANNELx where x can be (0..15). 
*                  - NewState: new state of the specified ADC DMA channels.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_DMAConfig(u16 ADC_DMAChannel, FunctionalState NewState )
{
  if (NewState == ENABLE)
  {
    /* select the DMA channel to be enabled */
    ADC->DMAR |= ADC_DMAChannel ;
  }
  else
  {
    ADC->DMAR &= ~ADC_DMAChannel;
  }
}

/*******************************************************************************
* Function Name  : ADC_DMACmd
* Description    : Enable or disable global DMA capability for the ADC.
* Input          : - NewState: new state of the ADC DMA capability.
*                    This parameter can be: ENABLE or DISABLE.
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_DMACmd (FunctionalState NewState)
{
  if (NewState == ENABLE)
  {
    /* Enable global DMA capability */
    ADC->DMAE |= ADC_DMA_Enable ;
  }
  else
  {
    ADC->DMAE &= ADC_DMA_Disable;
  }
}

/********************************************************************************
* Function Name  : ADC_DMAFirstEnabledChannel
* Description    : Return the first DMA enabled channel
* Input          : None
* Output         : None
* Return         : The first DMA enabled channel
********************************************************************************/
u16 ADC_DMAFirstEnabledChannel ( void )
{
  /* Return the DMA first enabled channel */
  return (ADC->DMAE & 0x000F);
}

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

⌨️ 快捷键说明

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