#include <mega128.h>

unsigned char index_state=0;

#define LONG_PULSE 40000;
#define SHORT_PULSE 10000;

#define PORT_C_RES PORTC=0
#define PORT_B_RES PORTB=0
#define PORT_F_RES PORTF=0 
#define PINB.1 b

unsigned char b;

flash char pc_state[]=
{
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000
};

flash char pb_state[]=
{
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000
};

flash char pf_state[]=
{
0b00000001,
0b00000010,
0b00000100,
0b00001000,
0b00010000,
0b00100000,
0b01000000,
0b10000000
};
 void timer1init(void)
{TCNT1 = 0x00;
TCCR1B=0x00;
TIMSK=0x04;
}
interrupt [TIM1_COMPA] void timer1_compa_isr(void)
{index_state++;    


switch (index_state)
  {
    case 1: PORTC=pc_state[0];
            OCR1A= LONG_PULSE;
            break;

    case 2:
            PORT_C_RES;
            OCR1A = SHORT_PULSE;
            break;
    case 3:
            PORTC=pc_state[1];
            OCR1A= LONG_PULSE;
            break;
    case 4:
            PORT_C_RES;
            OCR1A=SHORT_PULSE;
            index_state=0;
            break;
   // case 5:
          //  PORTC=pc_state[2];
           // OCR1A= LONG_PULSE;
           // break;
  //  case 6:
          //  PORT_C_RES;
          //  OCR1A=SHORT_PULSE;
          //  index_state=0;
          //  break;
};
}   
void main (void)
{
PORTC=0x00;
DDRC=0xFF;
PORTB=0x00;
DDRD=0xFF;
PORTF=0x00;
DDRF=0xFF;

ASSR=0x00;
TCCR0=0x00;
TCNT0=0x00;
OCR0=0x00;


//TCCR1=0x00;

TCNT1H=0x00;
TCNT1L=0x00;
ICR1H=0x00;
ICR1L=0x00;
OCR1A=0;
OCR1B=0x00;
OCR1CH=0x00;
OCR1CL=0x00;

EICRA=0x00;
EICRB=0x00;
EIMSK=0x00;

// Timer(s)/Counter(s) Interrupt(s) initialization
//TIMSK=0x20;
ETIMSK=0x00;

// Analog Comparator initialization
// Analog Comparator: Off
// Analog Comparator Input Capture by Timer/Counter 1: Off
ACSR=0x80;
SFIOR=0x00; 

#asm("sei")
//SREG=(1<<7);

while (1)
      {
     
        
        if (b==1)
        {timer1init();}
        if (index_state==20)
                {b=0;
                PORTC^=0;}
        else {b=1;}
      };
}
                           
                           