Skip to content

Instantly share code, notes, and snippets.

@Xplorer001
Last active August 29, 2015 14:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Xplorer001/48aad2429b398a976f92 to your computer and use it in GitHub Desktop.
Save Xplorer001/48aad2429b398a976f92 to your computer and use it in GitHub Desktop.
#include"adc.h"
#include"delay.h"
/***************************************************************************************************
void ADC_Init()
****************************************************************************************************
* I/P Arguments: none.
* Return value : none
* description :This function initializes the ADC module.
***************************************************************************************************/
void ADC_Init()
{
adc_Start=0; //Initialize all the control lines to zero.
adc_ALE=0;
adc_OE=0;
adc_EOC=1; //Configure the EOC pin as I/P
adc_databus=0xff; //configure adc_databus as input
}
***************************************************************************************************/
uint16_t ADC_GetAdcValue(uint8_t var_adcChannel_u8)
{
uint16_t adc_result;
adc_A=((var_adcChannel_u8>>0) & 0x01); //Selectthe channel
adc_B=((var_adcChannel_u8>>1) & 0x01); //for which the conversion needs to be done
adc_C=((var_adcChannel_u8>>2) & 0x01);
adc_ALE=1; // Latch the address by making the ALE high.
DELAY_us(50);
adc_Start=1; //Start the conversion after latching the channel address
DELAY_us(25);
adc_ALE=0; //Pull ALE line to zero after starting the conversion.
DELAY_us(50);
adc_Start=0; //Pull Start line to zero after starting the conversion.
while(adc_EOC==0); // Wait till the ADC conversion is completed,
// EOC will be pulled to HIGH by the hardware(ADC0809)
// once conversion is completed.
adc_OE=1; //Make the Output Enable high
//to bring the ADC data to port pins
DELAY_us(25);
adc_result=adc_databus; //Read the ADC data from ADC bus
adc_OE=0; //After reading the data, disable th ADC output line.
return(adc_result) ;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment