#include <avr/io.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

int	ticled;

//------------------------------------------------------------------------------
ISR (TIMER0_OVF_vect)				//Obsluha prerusenia TOV0 4ms
{
	PORTD ^= (1<<PORTD7);							//test osciloskop 
	ticled++;										//Led time = ticled * 4ms
	if (ticled == 0) PORTB |= (1<<PORTB5);			//Led ON 25 * 4 = 100ms
	else if (ticled == 25) PORTB &= ~(1<<PORTB5);	//Led OFF (250-25) * 4ms = 900ms
	else if (ticled == 249) ticled = -1; 		    //Clear Led time
	TCNT0 = 6; 										//Set TCNT0 on 4ms
}
//------------------------------------------------------------------------------
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 256 
	TIFR0 |= 1<<TOV0;					//Clear TOV0 flag
	TIMSK0 |= 1<<TOIE0;	  				//Enable TOV0
	TCNT0 = 6;							//Nastavenie TCNT0 
	sei();
	
	while(1) { 
		wdt_reset();
	}
}
//------------------------------------------------------------------------------

