#define F_CPU 16000000UL
#include <util/delay.h>
#include <avr/io.h>
int main(void)
{
DDRA=0;
//Declaring Port A as input
DDRB=255;
//Declaring port B as output
ADCSRA|=(1<<ADEN)|(1<<ADPS2) |(1<<ADPS1) |(1<<ADPS0);
// Enabled ADC and set prescaler division factor as 128
ADMUX|=(0<<REFS1)|(1<<REFS0)|(0<<MUX4)|(0<<MUX3)|(0<<MUX2)|(0<<MUX1)|(0<<MUX0)|(1<<ADLAR);
/*Vref is same as Vcc, Input constantly at Pin 0 of port A and Setting ADLAR to 1 left shifts the bits for an 8-bit precision*/
while(1)
{
ADCSRA|=(1<<ADSC);
//Start ADC
while((ADCSRA& (1<<6))!=0);
/*Do nothing till the conversion is over. Here, the condition that ADSC is cleared after conversion has been used. You can also use ADIF*/
PORTB = ADCH;
/*The ADC value stored in ADCH has been sent to PORT B as output.*/
_delay_ms(100);
};
}