//ICC-AVR application builder : 30.04.2012 18:07:50
// Target : T13
// Crystal: 1.2000Mhz

#include <iot13v.h>
#include <macros.h>

volatile unsigned char tic = 0;
volatile unsigned char flag_05;
void port_init(void)
{
 PORTB = 0x00;
 DDRB  = 0x00;
}

//TIMER0 initialize - prescale:1024
// WGM: Normal
// desired value: 10Hz
// actual value: 10,016Hz (0,2%)
void timer0_init(void)
{
 TCCR0B = 0x00; //stop
 TCNT0 = 0x8B; //set count
 TCCR0A = 0x00; 
 TCCR0B = 0x05; //start timer
}

#pragma interrupt_handler timer0_ovf_isr:iv_TIM0_OVF
void timer0_ovf_isr(void)
{
 TCNT0 = 0x8B; //reload counter value
 if(tic++ >= 20)
 {
   tic = 0;
   flag_05 = 1;// 0.5 Ρεκ
 }
}

//call this routine to initialize all peripherals
void init_devices(void)
{
 //stop errant interrupts until set up
 CLI(); //disable all interrupts
 port_init();
 timer0_init();

 MCUCR = 0x00;
 TIMSK0 = 0x02; //timer interrupt sources
 GIMSK = 0x00; //interrupt sources
 SEI(); //re-enable interrupts
 //all peripherals are now initialized
}

void main( void )
{
  unsigned char step = 0;
  unsigned char data[] = {0x01, 0x02, 0x04};
  init_devices();


while( 1 )
  {

for(i = 0; i < 9; i++)
{
  while(!flag_05);
  if(step++ < 3)
    PORTB = data[step];
  else
    step = 0;
}

PORTB = 0x00;

for(i = 0; i < 5; i++)
{
  while(!flag_05);
  if(!PORTB);
    PORTB = 0x07;
  else
    PORTB = 0x00;  
}

}
}