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

volatile int seven_led[] ={0x88, 0xEB, 0x4C, 0x49, 0x2B, 0x19, 0x38, 0x8B, 0x08, 0x0B};
volatile int ac_result=0, timer=0 ;


SIGNAL(SIG_COMPARATOR)
	{
	ac_result=( ACSR & (1<<ACO) ) ? 1 : 2;
	}


void enable_analog_compare_inturrupt(void)
	{ 
	ACSR= (1<<ACBG) | (1<<ACIE);
	}
	
SIGNAL(SIG_OVERFLOW0)
{
	timer++;
}	
	
int main(void)
	{
	
	DDRA = 0xFF ;
	DDRB = 0xFF ;
	TIMSK = 1<<TOIE0;
	ASSR = 1<<AS0;
	TCCR0 |= 0X05;
	
	enable_analog_compare_inturrupt();
	
	sei();	
		
		while(1) {
		 
		if(ac_result == 1){
		
		PORTB = (timer < 3) ? ( 1 << PB4) : 0;
		
		}
		
		else {
		
		timer=0;
		
		PORTB=0;
		
		}
		
		PORTA = seven_led[ac_result];
		
		}
	
}
