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

void inicializace();
inline void clearbit(volatile uint8_t &reg, uint8_t bit);
inline void setbitbit(volatile uint8_t &reg, uint8_t bit);
void displej(uint8_t pozice, uint8_t cislice);

int main(void)
{
  uint8_t pozice, cislice;
    
  inicializace();
  
  while (1)
  {
    for(pozice = 1; pozice <= 2; pozice++)
    {
      for(cislice = 0; cislice <= 15; cislice ++)
      {
        displej(pozice, cislice);
        _delay_ms(500);
      }
    }
  }
}

void inicializace()
{
  DDRB = (1 << 1);
  DDRC = (1 << 3);
  DDRD = 0b11111111;
}

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

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

void displej(uint8_t pozice, uint8_t cislice)
{
  const uint8_t dekoder[16] = 
    {0b00001100, 0b00111111, 0b01000101, 0b00100101,
     0b00110110, 0b10100100, 0b10000100, 0b00111101,
     0b00000100, 0b00100100, 0b00010100, 0b10000110,
     0b11001100, 0b00000111, 0b11000100, 0b11010100};
    
  if(pozice == 1)
  {
    clearbit(PORTC, 3);
    setbit(PORTB, 1);
  }
  else
  {
    setbit(PORTC, 3);
    clearbit(PORTB, 1);
  }

  PORTD = dekoder[cislice];
}
