Microcontroller › AVR › problem occurs in getting value from input adc channel in atmega 16 › use folloing library file for
March 31, 2013 at 4:20 am
#9399
sushant
Participant
use folloing library file for ADC communication,
#include<avr/io.h>
#include<adc_lib.h>
#define ADC_VREF_TYPE 0x00
// Read the AD conversion result
unsigned int read_adc(unsigned char adc_input)
{
ADMUX=adc_input|ADC_VREF_TYPE;
// Start the AD conversion
ADCSRA|=0x40;
// Wait for the AD conversion to complete
while ((ADCSRA & 0x10)==0);
ADCSRA|=0x10;
return ADCW;
}
// header file//
#include<avr/io.h>
unsigned int read_adc(unsigned char);
void ADCinit();
void ADCinit()
{
ADMUX=ADC_VREF_TYPE;
ADCSRA=0x85;
}