//
// A/D Example
// By PEK '2006
//
// Compiler: GCC
// MCU: ATMega48
//

#include <avr/io.h>
#include <avr/interrupt.h>

// Timer Compare Match ISR
ISR(TIMER1_COMPA_vect)
{
	uint8_t temp;

	temp = ADCH;	
	PORTB = temp >> 2;	// Only interested in 6 bits
}

int main(void)
{	
	// Initiate Ports
	PORTB = 0x00;
	DDRB = 0xFF;	// PortB as output

	PRR = ~(_BV(PRADC) | _BV(PRTIM1));	// Only enable ADC and Timer1

	// Initiate A/D (free running mode)
	ADMUX = _BV(ADLAR);	// AREF as reference, use ADCO as input, left adjustment
	DIDR0 = _BV(ADC0D);	// Disable digital input buffer on ADC0
	ADCSRA = _BV(ADEN) | _BV(ADSC) | _BV(ADATE) | _BV(ADPS1) | _BV(ADPS2);	// Set prescaler to 64, enable A/D and start conversions

	// Initiate Timer
	TCCR1B = _BV(WGM12) | _BV(CS12) | _BV(CS10);	// clk/1024 and Clear on match
	OCR1A = 976;	// Compare register, 1 sec at 1 MHz
	TIMSK1 = _BV(OCIE1A);	// Enable Compare match interrupt
	
	sei();

	while(1)
	{
		
	}
	
	return 1;
}





