#define F_CPU 16000000UL
#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 = 1;
  uint8_t cislice = 0;
  
  inicializace();
  
  while (1) 
  {
    displej(pozice, cislice);
	_delay_ms(500);
	
	cislice++;
	if(cislice == 16)
	{
	  cislice = 0;
	  
	  pozice++;
	  if(pozice == 3)
	    pozice = 1;
    }
  }
}

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)
{
  if(pozice == 1)
  {
    clearbit(PORTC, 3);
    setbit(PORTB, 1);
  }
  else
  {
    setbit(PORTC, 3);
    clearbit(PORTB, 1);
  }
	
  if(cislice == 0)
    PORTD = 0b00001100;
  if(cislice == 1)
    PORTD = 0b00111111;
  if(cislice == 2)
    PORTD = 0b01000101;
  if(cislice == 3)
    PORTD = 0b00100101;
  if(cislice == 4)
    PORTD = 0b00110110;
  if(cislice == 5)
    PORTD = 0b10100100;
  if(cislice == 6)
    PORTD = 0b10000100;
  if(cislice == 7)
    PORTD = 0b00111101;
  if(cislice == 8)
    PORTD = 0b00000100;
  if(cislice == 9)
    PORTD = 0b00100100;
  if(cislice == 0xA)
    PORTD = 0b00010100;
  if(cislice == 0xB)
    PORTD = 0b10000110;
  if(cislice == 0xC)
    PORTD = 0b11001100;
  if(cislice == 0xD)
    PORTD = 0b00000111;
  if(cislice == 0xE)
    PORTD = 0b11000100;
  if(cislice == 0xF)
    PORTD = 0b11010100;
}

