#include <reg51.h>

sbit P2_0 = P2^0;
sbit P2_1 = P2^1;
sbit P2_2 = P2^2;
sbit P2_3 = P2^3;
sbit P2_4 = P2^4;
sbit P2_5 = P2^5;
sbit P2_6 = P2^6;
sbit P2_7 = P2^7;

sbit P1_0 = P1^0;
sbit P1_1 = P1^1;
sbit P1_2 = P1^2;
sbit P1_3 = P1^3;

unsigned int row_data1[5][5]={
{1,1,1,1,1},
{0,1,0,0,0},
{0,0,1,0,0},
{1,1,1,1,1},
{1,1,1,1,1}
};
unsigned int word;
unsigned int i;
unsigned int j;

unsigned char row_data[5][5];
unsigned char loop_words;
unsigned char loop;
unsigned char loop1;
unsigned char a;
unsigned int row;
unsigned char delay;
unsigned char col;
unsigned char sr;

unsigned char msg[3];
unsigned char row_buff[6];

code unsigned char msg_org[3]={"ABC"};

main()
{
while (1)
{
word=0;
a=0;
  //strobe
   P1_0=0;

  //EO enable
P1_3=0;

for (sr=0;sr<7;sr++) {

row_buff[sr]=0; }

for (loop_words=0;loop_words<3;loop_words++) {
for (loop=0;loop<=5;loop++) {
for (loop1=0;loop1<50;loop1++) {
for (row=0;row<=5;row++)
 { 

for (word=0;word<=loop_words;word++) 
{
msg[word]=msg_org[word];

//WHEN I REMOVE THIS SWITCH IT WORKS PROPERLY

switch(msg[word])
{
case 'A':

  for (i=0;i<6;i++)
{
for (j=0;j<6;j++)
{row_data[i][j]=row_data1[i][j];
}
     }

	 break;
}
if (loop_words==0)
{
for (col=0;col<=loop;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }
 }//if loop words==0
 else if (loop_words>0)
 {
 if (word<loop_words)
 {
 for (col=0;col<=5;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }//for col
 }//for if

 else if (word=loop_words)
 {
 for (col=0;col<=loop;col++)
{
row_buff[a]=row_data[row][col];

 P1_1=row_buff[a] ;
 //clock
 P1_2=0;
P1_2=1;
 a=a+1;
 }//for col
}//for if
}//for if



}//for word



//PROBLEM

// "NOT INCREASING and every time P2_2 is zero"
if (row==0)
 P2_0=0 ;
 if (row==1) 
 P2_1=0 ;
if (row==2) 
 P2_2=0;
if (row==3)
  P2_3=0;
if (row==4) 
 P2_4=0;
    //strobe
   P1_0=1;
  //EO enable
P1_3=1;
 // delay
 for (delay=0;delay<200;delay++) {
 }
 //clr the buffer here
 for (sr=0;sr<6;sr++){
row_buff[sr]=0;
}
a=0;
//clr strobe
   P1_0=0;
//clr EO enable
P1_3=0;
//ports initializaion
 P2=0xFF;
//clr the SR
for (sr=0;sr<9;sr++){
P1_1=0;
//clock
P1_2=0;
P1_2=1;

}

}//for row

}//fr loop1
}//for loop
}//for loop_words
}//while
}//main
