#include <reg51.h>

code unsigned int row_data1[5][5]={
{0,1,1,1,0},
{0,1,0,1,0},
{0,1,0,1,0},
{0,1,1,1,0},
{0,1,0,1,0}
};
code unsigned int row_data2[5][5]={
{0,1,1,1,0},
{0,1,0,1,0},
{0,1,1,1,0},
{0,1,0,1,0},
{0,1,1,1,0}
};
code unsigned int row_data3[5][5]={
{0,1,1,1,0},
{0,1,0,0,0},
{0,1,0,0,0},
{0,1,0,0,0},
{0,1,1,1,0}
};
code unsigned int row_data4[5][5]={
{1,1,1,1,0},
{1,0,0,0,1},
{1,0,0,0,1},
{1,0,0,0,1},
{1,1,1,1,0}
};
code unsigned int row_data5[5][5]={
{0,1,1,1,1},
{0,1,0,0,0},
{0,1,1,1,1},
{0,1,0,0,0},
{0,1,1,1,1}
};
code unsigned int row_data6[5][5]={
{0,1,1,1,1},
{0,1,0,0,0},
{0,1,1,1,1},
{0,1,0,0,0},
{0,1,0,0,0}
};
code unsigned int row_data7[5][5]={
{0,0,1,1,1},
{0,1,0,0,0},
{0,1,0,1,0},
{0,1,0,0,1},
{0,0,1,1,0}
};
//space
code unsigned int row_data8[5][5]={
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0},
{0,0,0,0,0}
};
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 char word;
unsigned char i;


unsigned char row_data[5][5];
unsigned char loop_words;
unsigned char loop;
unsigned char loop1;
unsigned char row;
unsigned char d;
unsigned char col;

unsigned char row_buff[30];

code unsigned char msg_org[7]={"ABCDEFG"};

void main()
{



while (1)
{



//Clr the shift register
P1_1=0;
for (d=0;d<8;d++){

//clock
P1_2=0;
P1_2=1;

}
d=0;
  //strobe of shift register BU4094 is off.
   P1_0=0;
  //EO of shift register is also off.
P1_3=0;

for (loop_words=0;loop_words<7;loop_words++) {//the main loop


for (loop=0;loop<5;loop++) {//this is to select column data
for (loop1=0;loop1<7;loop1++) {//this loop refreshes the display 
for (row=0;row<=5;row++)//for selection of rows
 { 
for (word=0;word<=loop_words;word++)//This loop make it sure that initially 1st word is selected
//then 2 words and then 3 words of the original msg 
{

switch(msg_org[word])
{
    case 'A':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data1[i][d];
}
     }

	 break;
	 case 'B':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data2[i][d];
}
     }

	 break;
	 case 'C':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data3[i][d];
}
     }

	 break;
	 case 'D':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data4[i][d];
}
     }

	 break;
	     case 'E':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data5[i][d];
}
     }

	 break;
	     case 'F':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data6[i][d];
}
     }

	 break;
	     case 'G':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data7[i][d];
}
     }

	 break;	
  	 	     case ' ':

  for (i=0;i<5;i++)
{
for (d=0;d<5;d++)
{row_data[i][d]=row_data8[i][d];
}
     }

	 break;	  	  	 	 	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  	 	  
}




if (word==loop_words)//if this is first word then add only one bit to row_buff
{
for (col=0;col<=loop;col++)
{
row_buff[d]=row_data[row][col];

 P1_1=row_buff[d] ;
 //clock
 P1_2=0;
P1_2=1;
 d=d+1;
 }
 }//if loop words==0
 else//Now if word are more than 1 (i.e; loop_words>0) than add 5 bits of 1st character 
 {
for (col=0;col<=4;col++)
{
row_buff[d]=row_data[row][col];

 P1_1=row_buff[d] ;
 //clock
 P1_2=0;
P1_2=1;
 d=d+1;

 }//for if

 
}//for word loop

if (row==0)//if this the first row then off it so that it can be illuminated
 P2_0=0 ;
 if (row==1)//if this the 2nd row then off it so that it can be illuminated 
 P2_1=0 ;
if (row==2) //if this the 3rd row then off it so that it can be illuminated
 P2_2=0;
if (row==3)//if this the 4th row then off it so that it can be illuminated
  P2_3=0;
if (row==4) //if this the 5th row then off it so that it can be illuminated
 P2_4=0;
 //strobe to shift register
   P1_0=1;
  //EO enable
P1_3=1;
 // delay so that the leds can be illuminated fo a while
 for (d=0;d<250;d++) {
 } 
   

d=0;
//clr strobe
   P1_0=0;
//clr EO 
P1_3=0;
//row is shut-off
 P2=0xFF;
//clr the SR
P1_1=0;
for (d=0;d<8;d++){

//clock
P1_2=0;
P1_2=1;

}



 
}//for row

}//fr loop1
}//for loop
}//for loop_words
}//while
}//main


