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

📄 75x_adc.c

📁 ST的ARM7芯片完整DEMO程序。 具备点阵液晶显示器
💻 C
📖 第 1 页 / 共 3 页
字号:
}

/*******************************************************************************
* Function Name  : ADC_ITConfig
* Description    : Enables or disables the specified ADC interrupts.
* Input          : - ADC_IT: specifies the ADC interrupts to be enabled or disabled.
*                    This parameter can be any combination of the following values:
*                         - ADC_IT_ECH:  End of chain conversion interrupt
*                         - ADC_IT_EOC:  End of channel conversion interrupt
*                         - ADC_IT_JECH: Injected end of chain conversion interrupt
*                         - ADC_IT_JEOC: Injected end of channel conversion interrupt
*                         - ADC_IT_AnalogWatchdog0_LowThreshold:
*                                        Analog Watchdog 0 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog0_HighThreshold:
*                                        Analog Watchdog 0 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_LowThreshold:
*                                        Analog Watchdog 1 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_HighThreshold:
*                                        Analog Watchdog 1 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_LowThreshold:
*                                        Analog Watchdog 2 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_HighThreshold:
*                                        Analog Watchdog 2 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_LowThreshold:
*                                        Analog Watchdog 3 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_HighThreshold:
*                                         Analog Watchdog 5 HighThreshold interrupt
*                         - ADC_IT_ALL:  All interrupts
*                  - 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)
  {
    /* Enable the selected ADC interrupts */
    ADC->IMR |= ADC_IT;
  }
  else
  {
    /* Disable the selected ADC interrupts */
    ADC->IMR &= ~ADC_IT;
  }
}

/*******************************************************************************
* Function Name  : ADC_DMAConfig
* Description    : Configures the ADC抯 DMA interface.
* Input          : - ADC_DMA_CHANNEL: specifies the channels to be enabled or 
*                    disabled for DMA transfer. 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_DMA_CHANNEL, FunctionalState NewState)
{
  if(NewState == ENABLE)
  {
    /* Enable DMA for the selected channels */
    ADC->DMAR |= ADC_DMA_CHANNEL ;
  }
  else
  {
    /* Disable DMA for the selected channels */
    ADC->DMAR &= ~ADC_DMA_CHANNEL;
  }
}

/*******************************************************************************
* Function Name  : ADC_DMACmd
* Description    : Enable or disable the DMA transfer for the ADC.
* Input          : - ADC_DMA: specifies the DMA command. This parameter can be 
*                    one of the following values:
*                         - ADC_DMA_Disable: disable the DMA capability
*                         - ADC_DMA_Enable: enabled by setting the global 
*                           enable bit
*                         - ADC_DMA_ExtTrigger_HighLevel: enabled by detection of
*                           high level of TIM2 OC2 signal
*                         - ADC_DMA_ExtTrigger_LowLevel: enabled by detection of
*                           low level of TIM2 OC2 signal
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_DMACmd(u16 ADC_DMA)
{
  /* Configure the DMA external trigger enable */
  switch (ADC_DMA)
  {
    case ADC_DMA_Disable :
      /* Disable DMA transfer */
      ADC->DMAE &= ADC_DMA_Disable;
      break;
      
    case ADC_DMA_Enable :
      /* Enable DMA transfer */
      ADC->DMAE |= ADC_DMA_Enable;
      break;
      
    case ADC_DMA_ExtTrigger_HighLevel :
      /* Enable DMA transfer on high level of the external trigger (TIM2) */
      ADC->DMAE &= ADC_DMA_Disable;
      ADC->DMAE |= ADC_DMA_ExtTrigger_HighLevel;
      break;
      
    case ADC_DMA_ExtTrigger_LowLevel :
      /* Enable DMA transfer on low level of the external trigger (TIM2) */
      ADC->DMAE |= ADC_DMA_ExtEnable_Mask; 
      ADC->DMAE &= ADC_DMA_ExtTrigger_LowLevel;
      break;

    default:
      break;      
  }  
}

/*******************************************************************************
* Function Name  : ADC_GetDMAFirstEnabledChannel
* Description    : Gets the first DMA-enabled channel configured at the time that
*                  DMA was last globally enabled.
* Input          : None
* Output         : None
* Return         : The first DMA enabled channel
*******************************************************************************/
u16 ADC_GetDMAFirstEnabledChannel(void)
{
  /* Return the DMA first enabled channel */
  return (ADC->DMAE & ADC_DMAFirstEnabledChannel_Mask);
}

/*******************************************************************************
* Function Name  : ADC_GetFlagStatus
* Description    : Checks whether the specified ADC flag is set or not.
* Input          : - ADC_FLAG: specifies the ADC flag to check. This parameter 
*                    can be one of the following values:
*                         - ADC_FLAG_ECH:  End of chain conversion Flag
*                         - ADC_FLAG_EOC:  End of channel conversion Flag
*                         - ADC_FLAG_JECH: End of injected chain conversion Flag
*                         - ADC_FLAG_JEOC: End of injected channel conversion Flag
*                         - ADC_FLAG_AnalogWatchdog0_LowThreshold:  
*                                          Analog Watchdog 0 LowThreshold Flag        
*                         - ADC_FLAG_AnalogWatchdog0_HighThreshold: 
*                                          Analog Watchdog 0 HighThreshold Flag 	
*                         - ADC_FLAG_AnalogWatchdog1_LowThreshold:  
*                                          Analog Watchdog 1 LowThreshold Flag  	
*                         - ADC_FLAG_AnalogWatchdog1_HighThreshold: 
*                                          Analog Watchdog 1 HighThreshold Flag  	
*                         - ADC_FLAG_AnalogWatchdog2_LowThreshold:  
*                                          Analog Watchdog 2 LowThreshold Flag  	
*                         - ADC_FLAG_AnalogWatchdog2_HighThreshold: 
*                                          Analog Watchdog 2 HighThreshold Flag 	
*                         - ADC_FLAG_AnalogWatchdog3_LowThreshold:  
*                                          Analog Watchdog 3 LowThreshold Flag  	
*                         - ADC_FLAG_AnalogWatchdog3_HighThreshold: 
*                                          Analog Watchdog 3 HighThreshold Flag 
* Output         : None	
* Return         : The new state of the ADC_FLAG (SET or RESET).
*******************************************************************************/
FlagStatus ADC_GetFlagStatus(u16 ADC_FLAG)
{
  /* Check the status of the specified ADC flag */
  if((ADC->PBR & ADC_FLAG) != RESET)
  {
    /* Return SET if ADC_FLAG is set */
    return SET;
  }
  else
  {
    /* Return RESET if ADC_FLAG is reset */
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : ADC_ClearFlag
* Description    : Clears the ADC抯 pending flags.  
* Input          : - ADC_FLAG: specifies the flag to clear. This parameter can 
*                    be any combination of the following values:
*                         - ADC_FLAG_ECH:  End of chain conversion flag
*                         - ADC_FLAG_EOC:  End of channel conversion flag
*                         - ADC_FLAG_JECH: Injected end of chain conversion flag
*                         - ADC_FLAG_JEOC: Injected end of channel conversion flag
*                         - ADC_FLAG_AnalogWatchdog0_LowThreshold:  
*                                         Analog Watchdog 0 LowThreshold flag        
*                         - ADC_FLAG_AnalogWatchdog0_HighThreshold: 
*                                         Analog Watchdog 0 HighThreshold flag 	
*                         - ADC_FLAG_AnalogWatchdog1_LowThreshold:  
*                                         Analog Watchdog 1 LowThreshold flag  	
*                         - ADC_FLAG_AnalogWatchdog1_HighThreshold: 
*                                         Analog Watchdog 1 HighThreshold flag  	
*                         - ADC_FLAG_AnalogWatchdog2_LowThreshold:  
*                                         Analog Watchdog 2 LowThreshold flag  	
*                         - ADC_FLAG_AnalogWatchdog2_HighThreshold: 
*                                         Analog Watchdog 2 HighThreshold flag 	
*                         - ADC_FLAG_AnalogWatchdog3_LowThreshold:  
*                                         Analog Watchdog 3 LowThreshold flag  	
*                         - ADC_FLAG_AnalogWatchdog3_HighThreshold: 
*                                         Analog Watchdog 3 HighThreshold flag  	
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_ClearFlag(u16 ADC_FLAG)
{
  /* Clear the selected ADC flag */ 
  ADC->PBR = ADC_FLAG;
}

/*******************************************************************************
* Function Name  : ADC_GetITStatus
* Description    : Checks whether the specified ADC interrupt has occured or not.
* Input          : - ADC_IT: specifies the ADC interrupt source to check. This 
*                    parameter can be one of the following values:
*                         - ADC_IT_ECH :End of chain conversion interrupt 
*                         - ADC_IT_EOC :End of channel conversion interrupt
*                         - ADC_IT_JECH :End of injected chain conversion interrupt
*                         - ADC_IT_JEOC :End of injected channel conversion interrupt
*                         - ADC_IT_AnalogWatchdog0_LowThreshold:  
*                                         Analog Watchdog 0 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog0_HighThreshold: 
*                                         Analog Watchdog 0 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_LowThreshold:  
*                                         Analog Watchdog 1 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_HighThreshold: 
*                                         Analog Watchdog 1 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_LowThreshold:  
*                                         Analog Watchdog 2 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_HighThreshold: 
*                                         Analog Watchdog 2 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_LowThreshold:  
*                                         Analog Watchdog 3 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_HighThreshold: 
*                                         Analog Watchdog 3 HighThreshold interrupt
* Output         : None	
* Return         : The new state of the ADC_IT (SET or RESET).
*******************************************************************************/
ITStatus ADC_GetITStatus(u16 ADC_IT)
{
  /* Check the status of the specified ADC interrupt */
  if((ADC->PBR & ADC_IT) != RESET)
  {
    /* Return SET if the ADC interrupt flag is set */
    return SET;
  }
  else
  {
    /* Return RESET if the ADC interrupt flag is reset */
    return RESET;
  }
}

/*******************************************************************************
* Function Name  : ADC_ClearITPendingBit
* Description    : Clears the ADC抯 interrupt pending bits.  
* Input          : - ADC_IT: specifies the interrupt pending bit to clear. This 
*                    parameter can be can be any combination of the following 
*                    values:
*                         - ADC_IT_ECH:  End of chain conversion interrupt
*                         - ADC_IT_EOC:  End of channel conversion interrupt
*                         - ADC_IT_JECH: Injected end of chain conversion interrupt
*                         - ADC_IT_JEOC: Injected end of channel conversion interrupt
*                         - ADC_IT_AnalogWatchdog0_LowThreshold:  
*                                         Analog Watchdog 0 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog0_HighThreshold: 
*                                         Analog Watchdog 0 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_LowThreshold:  
*                                         Analog Watchdog 1 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog1_HighThreshold: 
*                                         Analog Watchdog 1 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_LowThreshold:  
*                                         Analog Watchdog 2 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog2_HighThreshold: 
*                                         Analog Watchdog 2 HighThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_LowThreshold:  
*                                         Analog Watchdog 3 LowThreshold interrupt
*                         - ADC_IT_AnalogWatchdog3_HighThreshold: 
*                                         Analog Watchdog 5 HighThreshold interrupt
* Output         : None
* Return         : None
*******************************************************************************/
void ADC_ClearITPendingBit(u16 ADC_IT)
{
  /* Clear the selected ADC interrupts pending bits */
  ADC->PBR = ADC_IT;
}

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

⌨️ 快捷键说明

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