void adc_init(void) { ADCSRA=0X00; flags ADMUX=0X60; ADCSRA=0X87; conversion, and the 128 ACSRA=0X80; }
// Function to initialise the ADC feature // Clear previous ADC results and status // 0x40 for 10 bits // We have set the ADSC bit to start a // ADPS bits are set so that the prescaler is // ADEN is set, to enable the ADC
unsigned char adc_start(unsigned char channel) // Function to perform an ADC conversion, Takes 0-8 as input // to select which input to convert { unsigned char i; ADCH=0x00; // Clear the previous result i=channel&0x07; conversion on ADMUX=i|0x60; the ADC control register ADCSRA|=1<
// Decide which line to perform ADC // Enter which line to perform in
// wait for conv. to complete //unsigned int temp=ADC; for 10
/* ---------------- Sample ADC Call -----------------------*/ unsigned char result=adc_start(0); Pin A0 and stores the result
// This performs ADC conversion on // to variable "result"