#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

int	ticled;

//------------------------------------------------------------------------------
ISR (TIMER0_OVF_vect)               //Obsluha prerusenia TCO 1,008ms
{	
	PORTD ^= (1<<PORTD7);								//test osciloskop
	ticled++;
	if (ticled == 0) PORTB |= (1<<PORTB5);				//50ms svieti
	else if (ticled == 50) PORTB &= ~(1<<PORTB5);		//200ms nesvieti
	else if (ticled == 250) PORTB |= (1<<PORTB5);		//50ms svieti
	else if (ticled == 300) PORTB &= ~(1<<PORTB5);		//700ms nesvieti
	else if (ticled == 999) ticled = -1;
	TCNT0 = 193;									//Set TCNT0 (1,008ms)
}
//------------------------------------------------------------------------------
int main (void) {
	
	wdt_enable(WDTO_500MS);			//povolenie WDT 0,5sec
	DDRB |= (1<<DDB5);				//nastavenie LED na vystup 
	DDRD |= (1<<DDD7);				//nastavenie vystup pre osciloskop
	ticled = -1;
	
	//TC0 - normal mode,
	TCCR0B |= (1<<CS02);			//Set prescaler to 256 Timer clock = system clock/256
	TIFR0 |= 1<<TOV0;				//Clear TOV0 flag
	TIMSK0 |= 1<<TOIE0;	  			//Enable Timer0 overflow interrupt
	TCNT0 = 193;				    //Nastavenie TCNT0 podla BOTTOM
	sei();
	
	while(1) { 
		wdt_reset();
	}
}
//------------------------------------------------------------------------------

