#include <avr/io.h>
#include <avr/interrupt.h>



volatile int timer1_overflows;


int main(void)
{
	DDRC = 0xFF;
	DDRB = 0x00;
	PORTB = 0xFF;



		//enable interrupts
	sei();
		

		//TIMER0 setup:
		//prescaling (1: 001 / 8: 010 / 64: 011 / 256: 100 / 1024: 101)
	TCCR0B |= (0<<CS02) | (0<<CS01) | (1<<CS00);
		
		//TIMER1 setup:
		//Input Capture Noise Canceler enable
		//Input Capture Edge Select (falling edge)	
	TCCR1B |= (1<<ICNC1) | (0<<ICES1);
		//prescaling (1: 001 / 8: 010 / 64: 011 / 256: 100 / 1024: 101)
	TCCR1B |= (0<<CS12) | (0<<CS11) | (1<<CS10);

		//Input Capture Interrupt Enable
		//Timer1 Overflow Interrupt Enable
	TIMSK1 |= (1<<ICIE1) | (1<<TOIE1);

	
	while(1)
	{
		if(PINB & 0x02)
		{
			OCR0A = 0x42;	
		}
		else
		{
			OCR0A = 0x9C;	
		}

	}

	return 0;
}

	
ISR( TIMER1_CAPT_vect )
{
	
		
		PORTC = 0x00;
		TCNT0 = 0x00;
		
		//Output Compare Match A Interrupt Enable 
		TIMSK0 |= (1<<OCIE0A);
}


ISR ( TIMER0_COMPA_vect )
{
	PORTC = 0xFF;
		//Output Compare Match A Interrupt Disable 
	TIMSK0 |= (0<<OCIE0A);

}

ISR( TIMER1_OVF_vect )
{
		//Für spätere Berechnung der Frequenz
		//count TIMER1 overflows
	++timer1_overflows;
}
