#define F_CPU 16000000UL
#include <avr/io.h>
#include <util/delay.h>
#include <avr/wdt.h>
#include <avr/interrupt.h>

const uint8_t maskaLED = 1 << 5;

#define sw_reset() __asm__ __volatile__ ("jmp 0")

int main(void)
{
  DDRB = maskaLED;
  
  //nulovani WDT:
  wdt_reset();
  //povoleni zmeny intervalu:
  WDTCSR = (1 << WDCE) | (1 << WDE);
  //povoleni preruseni a zmena intervalu 1000 ms:
  WDTCSR = (1 << WDIE) | (1 << WDP2) | (1 << WDP1);
  
  sei();
  
  while (1)
  {
    wdt_reset();
    _delay_ms(500); 
    PORTB = PORTB ^ maskaLED;
  }
}

//obsluha WDT preruseni:
ISR(WDT_vect)
{
  PORTB = PORTB | maskaLED;
  sw_reset();
}

