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

//porty a bity pro obe LED:
volatile uint8_t &portLED1 = PORTB;
volatile uint8_t &portLED2 = PORTD;
const uint8_t bitLED1 = 5;
const uint8_t bitLED2 = 2;

void inicializace()
{
  DDRB = (1 << bitLED1);  //PB5 vystup
  DDRD = (1 << bitLED2);  //PD2 vystup

  //normalni rezim, D = 256:
  TCCR4A = 0;
  TCCR4B = (1 << CS42);
  TIMSK4 = (1 << TOIE4);  //povoleni preruseni
}

int main(void)
{
  inicializace();
  sei();  //preruseni povoleno

  while (1)
  {
  }
}

inline void negbit(volatile uint8_t &reg, uint8_t bit)
{
  reg = reg ^ (1 << bit);
}

//obsluha preteceni c/c 4:
ISR(TIMER4_OVF_vect)
{
  negbit(portLED1, bitLED1);
  negbit(portLED2, bitLED2);
}