#include <avr/io.h>
void adc_init(void); // A/D converter initialization
int main(void)
{
unsigned int buffer;
adc_init(); // Init A/D converter
while (1)
{
ADCSRA |= (1<<ADSC); // Start A/D conversion
while ( !(ADCSRA & (1<<ADIF)) /* Do nothing */ ; // Wait until AD not finished
buffer = (ADCH<<8) | ADCL; // Then, read result
}
}
void adc_init(void) // A/D converter initialization
{
ADMUX = 0; // Ref: external, Channel 0 (ADC0)
ADCSRA = (1<<ADEN)|(1<<ADPS2)|(1<<ADPS1); // A/D ON, prescaler = 64,
SFIOR = 0; // Specialfunctions OFF
}