?? adc.c
字號:
/*
******************************************************************************
COPYRIGHT 2003 STMicroelectronics
Source File Name : adc.c
Group : IPSW,CMG-IPDF
Author : MCD Application Team
Date First Issued: 6/3/2002
********************************Documentation*********************************
General Purpose - This file contains source code for all the functions defined
in adc.h.
********************************RevisionHistory*******************************
______________________________________________________________________________
Date :06/03/2002 Release:1.0
Date :22/09/2003 Release:2.0
1.Modified the code for supporting new devices i.e. DALI,
whole LITE family,72F561,72F264,72F62.
2.Included necessary comments.
3.Removed the description of functions which are changed
to macro.
******************************************************************************/
#include "ST7lib_config.h" /* Selection of device*/
#include "adc_hr.h" /* Declaration of the constants used in adc.c*/
#include "adc.h" /* Declaration of functions used in top level file*/
/*-----------------------------------------------------------------------------
ROUTINE NAME : ADC_Init
INPUT : ADC_SPEED (Sets the Clock of ADC)
ADC_ONESHOT (Configures the ADC in oneshot mode)
ADC_IT_ENABLE (Enables the Interrupt)
ADC_AMPLIFIER_ON (Enables the Amplifier)
ADC_AMPLIFIER_CAL (Calibrates the Amplifier)
ADC_SLOW (Sets the Clock of ADC)
ADC_DEFAULT (Configures the ADC in Default mode)
OUTPUT : None.
DESCRIPTION : ADC peripheral initialisation routine.
COMMENTS : User has to pass the InitValue from INPUT.More than one
INPUT parameters can be passed by Logically ORing the INPUTs
-----------------------------------------------------------------------------*/
void ADC_Init (Typ_ADC_InitParameter InitValue)
{
unsigned char Temp; /* Only for reading the registers */
#if (defined ADC_72F521 || defined ADC_72F62 || defined ADC_72F561 ||\
defined ADC_72F264)
ADCCSR = ADC_DEFAULT; /* Clear ADC control status register */
ADCCSR = (unsigned char)InitValue; /* Clear the ADC data register*/
Temp = ADCDRH; /* Clear EOC flag*/
#endif
#if (defined ADC_72F63 || defined ADC_72F65)
ADCCSR = ADC_DEFAULT; /* Clear ADC control status register */
ADCCSR = (unsigned char)InitValue; /* Clear the ADC data register*/
Temp = ADCDR; /* Clear EOC flag*/
#endif
#if (defined ADC_LITE0 || defined ADC_SUPERLITE)
ADCCSR = ADC_DEFAULT; /* Clear ADC control status register */
ADCAMP = ADC_DEFAULT;
ADCAMP = (unsigned char)InitValue; /* Initialise ADC amplifier */
if((unsigned char)InitValue & ADC_SPEED_SET)
{
ADCCSR = ADC_SPEED_SET; /* Set SPEED bit */
}
Temp = ADCDR; /* Clear EOC flag */
#endif
#ifdef ADC_DALI
ADCCSR = ADC_DEFAULT; /* Clear ADC control status register */
ADCDRL = ADC_DEFAULT; /* Clear the ADC data register*/
ADCDRL = (unsigned char)InitValue;
/* Initialise ADC Data Low Register */
if((unsigned char)InitValue & ADC_SPEED_SET)
{
ADCCSR = ADC_SPEED_SET; /* Set SPEED bit */
}
Temp = ADCDRH; /* Clear EOC flag*/
#endif
#if (defined ADC_LITE1 || defined ADC_LITE2 || defined ADC_LITE3)
ADCCSR = ADC_DEFAULT; /* Clear ADC control status register */
ADCDRL = ADC_DEFAULT; /* Clear the ADC data register*/
ADCDRL = (unsigned char)InitValue;
/* Initialise ADC Data Low Register */
if((unsigned char)InitValue & ADC_SPEED_SET)
{
ADCCSR = ADC_SPEED_SET; /* Set SPEED bit */
}
Temp = ADCDRH; /* Clear EOC flag*/
#endif
}
/* ---------------------------------------------------------------------------
ROUTINE NAME : ADC_Test_Conversn_Complete
INPUT : None
OUTPUT : TRUE or FALSE
DESCRIPTION : Check if the A/D Conversion is complete.
COMMENTS : This function can be looped till the convertion is complete.
----------------------------------------------------------------------------*/
BOOL ADC_Test_Conversn_Complete (void)
{
if(ADCCSR & ADC_EOC) /* Check the EOC bit */
{
return(TRUE); /* Return the status of the EOC flag */
}
else
{
return(FALSE);
}
}
/* ----------------------------------------------------------------------------
ROUTINE NAME : ADC_Select_Channel
INPUT : ADC_AIN (Channel no.)
OUTPUT : None
DESCRIPTION : Selects Analog input channel 0,1,2,3........15
COMMENTS : ADC_AIN depends upon the device used
----------------------------------------------------------------------------*/
void ADC_Select_Channel (unsigned char ADC_AIN)
{
#if (defined ADC_LITE0 || defined ADC_SUPERLITE ||defined ADC_LITE1 || defined ADC_LITE2 ||\
defined ADC_LITE3)
/* Select the analog channel for the conversion */
ADCCSR &= ADC_SEL_CHNL1;
ADCCSR |= ADC_AIN; /* Pass the value of the channel*/
#endif
#if (defined ADC_72F65 || defined ADC_72F264 || defined ADC_DALI ) /* Select the analog channel for the conversion */
ADCCSR &= ADC_SEL_CHNL1;
ADCCSR |= ADC_AIN; /* Pass the value of the channel */
#endif
#ifdef ADC_72F62
/* Select the analog channel for the conversion */
ADCCSR &= ADC_SEL_CHNL2;
ADCCSR |= ADC_AIN; /* Pass the value of the channel */
#endif
#if (defined ADC_72F63 || defined ADC_72F561 || defined ADC_72F521)
/* Select the analog channel for the conversion */
ADCCSR &= ADC_SEL_CHNL1;
ADCCSR |= ADC_AIN; /* Pass the value of the channel */
#endif
}
/* ----------------------------------------------------------------------------
ROUTINE NAME : ADC_Conversn_Read
INPUT : None
OUTPUT : unsigned integer (converted data from Data registers)
DESCRIPTION : Read the Conversion from the data register
COMMENTS : It returns OUTPUT,depending upon the device selceted
----------------------------------------------------------------------------*/
#if (defined ADC_72F561 || defined ADC_72F521 || defined ADC_72F62 ||\
defined ADC_72F264 || defined ADC_DALI ||defined ADC_LITE1 || defined ADC_LITE2 ||\
defined ADC_LITE3)
unsigned int ADC_Conversn_Read (void)
{
unsigned char Temp; /* Only for reading the registers */
unsigned int Conv_Data; /* for reading the converted data */
/* Reading the least two bits of conversion from ADCDRL*/
Temp = (unsigned char)((unsigned char)ADCDRL & (unsigned char)0x03);
Conv_Data = ADCDRH; /* reading the MSB of conversion */
Conv_Data = Conv_Data<< 2;
Conv_Data |= Temp; /* Oring the least two bits with the MSB */
return(Conv_Data); /* Returning the Converted data */
}
#endif
/************** (c) 2003 ST Microelectronics ****************** END OF FILE */
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -