#include #include "uart.h" void init(); //Initalizes UART, ADC. uint16_t do_adc(); //Starts an ADC conversion on ADC0 (PA0), waits for //conversion to finish, and returns 10-bit adc value. int main(void) { uint16_t adc_value; //Unsigned integer to hold the ADC value. init(); while(1) { adc_value = do_adc(); //Add your code here. } return 0; } void init() { //Init ADC. See the ATmega 16 datasheet for more info. ADMUX = _BV(REFS0); //Set the ADC voltage reference to AVCC (Analog voltage in) ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0); //Enable the ADC and set PS. //Init UART uart_init(); } uint16_t do_adc() { //Start an ADC conversion by setting the ADSC bit. ADCSRA |= _BV(ADSC); //Wait for the conversion to finish. The ADC signals that it's finished // by clearing the ADSC bit that we set above. while( ADCSRA & _BV(ADSC) ) ; //Do nothing. //Return the ADC result from the ADC register. return ADC; }