#define No_Op 0
#define No_Op_d 0
void SPI_INIT()
{
  volatile char *dir_b,*outB,*spcr;  // initialization of portb and control register
  dir_b=0x24;// address of data direction port B 
  outB=0x25;  // Address of output port B
  spcr=0x4c;  // Address of control register 
  *dir_b=0x07; // output mode - DIN, SCK
  *outB=0x01;  // SS= 1;
  *spcr=0x51; 
}
void SPI_TRANSMIT(char ch)
{
 volatile char *spdr,*spsr;
 spsr=0x4d;
 *spsr=0x00;
 spdr=0x4e;
 *spdr=ch;

 while(!*spsr);
 delay(5);

}
void TransmitByte(char address,char data,char matrixNo)
{
  volatile char *dir_b,*outB;
  dir_b=0x24;
  outB=0x25;
*dir_b=0x01;

  *outB=0x00;
  SPI_TRANSMIT(address);
  SPI_TRANSMIT(data);
  for(char z=1;z<matrixNo;z++)
  {
  SPI_TRANSMIT(No_Op);
  SPI_TRANSMIT(No_Op_d);
  }
  *outB=0x01;
}
void setup() {
  // put your setup code here, to run once:
  SPI_INIT();

}
void loop() 
{
  volatile char Row_select1=0x01,Row_select2=0x01,Row_select3=0x01,Row_select4=0x01,Row_select5=0x01,Row_select6=0x01,Row_select7=0x01;
  volatile char matrixNo=4,Column_select[]=
      { 
    0b11000011, 
    0b11000011,
    0b11000011,
    0b11000011,
    0b11011011,
    0b11111111,
    0b11100111,
    0b11000011, // W

    0b00000000,
    0b00000000,
     0b00000000,
    0b00111100,
    0b01100110,
   0b01111110,
     0b00000110,
   0b00111100, // e

    0b00000110,
  0b00000110,
    0b00000110,
   0b00000110,
    0b00000110,
   0b00000110,
   0b00000110,
    0b00001100, // l

0b00000000,
  0b00000000,
    0b00000000,
       0b00111100,
          0b00110110,
           0b00000110,
            0b00000110,
                0b00111100,
                // c
 0b00000000,
    0b00000000,
    0b00000000,
   0b00111100,
    0b01100110,
     0b01100110,
    0b01100110,
   0b00111100,
     // o

     
   0b00000000, 
    0b00000000, 
     0b01101110,
     0b11011011,
    0b11011011,
   0b11011011,
0b11011011,
0b11011011,
    // m

    0b00000000,
    0b00000000,
     0b00000000,
    0b00111100,
    0b01100110,
   0b01111110,
     0b00000110,
   0b00111100, // e
    };
for(char i=0;i<8;i++)
{
  TransmitByte(Row_select1++,Column_select[i],7);

   TransmitByte(Row_select2++,Column_select[i+8],6);

    TransmitByte(Row_select3++,Column_select[i+16],5);

     TransmitByte(Row_select4++,Column_select[i+24],4);

      TransmitByte(Row_select5++,Column_select[i+32],3);

   TransmitByte(Row_select6++,Column_select[i+40],2);

    TransmitByte(Row_select7++,Column_select[i+48],1);
}
}