1
\$\begingroup\$
#include <reg51.h> 
#include <intrins.h>
#define dport P2 

//This code is driver for graphics lcd which is 128x64 

sbit rs = P3^0 ; 
sbit rw = P3^1 ; 
sbit en = P3^2 ; 
sbit cs1 = P3^3 ; 
sbit cs2 = P3^4 ; 

unsigned char c,z=0;
unsigned char ar0[]={124,126,19,19,126,124,0,0};    //A,8x8
unsigned char ar1[]={65,127,127,73,127,54,0,0};     //B,8x8
unsigned char ar2[]={28,62,99,65,65,99,34,0};       //C,8x8
unsigned char ar3[]={65,127,127,65,99,62,28,0};     //D,8x8
unsigned char ar4[]={65,127,127,73,93,65,99,0,};    //E,8x8
unsigned char ar5[]={ 65,127,127,73,29,1,3,0};      //F,8x8
unsigned char ar6[]={ 28,62,99,65,81,115,114,0};    //G,8x8
unsigned char ar7[]={127,127,8,8,127,127,0,0};      //H,8x8

unsigned char ar00[]={126,17,17,17,126};        //A,5x7
unsigned char ar11[]={127,73,73,73,54};             //B,5x7
unsigned char ar22[]={62,65,65,65,34};          //C,5x7
unsigned char ar33[]={127,65,65,34,28};         //D,5x7
unsigned char ar44[]={127,73,73,73,65};         //E,5x7
unsigned char ar55[]={127,9,9,1,1};         //F,5x7
unsigned char ar66[]={62,65,65,81,50};          //G,5x7
unsigned char ar77[]={127,8,8,8,127};           //H,5x7

void ctrloff()
{
rs = 0 ;
rw = 0 ;
en = 0 ;
cs1 = 0 ; 
cs2 = 0 ;
}

void displayon()
{
ctrloff() ;
dport = 0x3F ;  // switching on the display command 
cs1 = 1 ;
cs2 = 1 ;
rw = 0 ;
rs = 0 ;
en = 1 ;
_nop_();
en = 0 ;
}
void delay()
{
int i ;
for( i = 0 ; i < 12750 ; i++ ) ;
}
void setcolumn( unsigned char y )
{
if( y < 64 )    
{
    ctrloff() ;
    c = y ;
    dport = 0x40|(y&63) ; // the command is b01(six bits for the column select)
    cs1 = 1 ; cs2 = 0 ;
    rs = 0 ; rw = 0 ;
    en = 1 ;
    _nop_() ;
    en = 0 ;
}
else
{
    ctrloff() ; 
    c = y ;
    dport = 0x40|(y-64) ;
    cs1 = 0 ; cs2 = 1 ;
    rs = 0 ; rw = 0 ;
    en = 1 ;
    _nop_() ;
    en = 0 ;
}
}

void setpage( unsigned char x )  // function for setting the page 
{
ctrloff() ;
dport = 0xb8 | x ;  // the command is b10111011 for setting the fourth page , the last three bits select the page 
cs1 = 0; cs2 = 0 ;
rs = 0 ; rw = 0 ;
en = 1 ;
_nop_() ;
en = 0 ; 
}

void lcddata(unsigned char* value , unsigned char limit ) // function for setting the  data from a particular position 
{
unsigned char i ;
for( i = 0 ; i < limit ; i++ )
{
        if( c<64 ) 
        {
            setcolumn(c)
            dport = value[i] ;
            cs1 = 0 ; cs2 = 0 ;
            rs = 1 ;
            rw = 0 ;
            en = 1 ;
            _nop_();
            en = 0 ;  
        }
        else 
        {
            setcolumn(c);
            dport = value[i] ;
            cs2 = 0 ; cs1 = 1 ; 
            rs = 1 ;
            rw = 0 ;
            en = 1;
            _nop_() ;
            en = 0 ;
            c++ ;
        }
    if(c > 127 )
    return ;
}
}

void clrlcd()
{
unsigned char i,j ;
for( i = 0 ; i < 8 ; i++ )
{
    setpage(i) ;
    setcolumn(0);
    for( j = 0 ; j < 128 ; j++ )
        lcddata(&z,1) ;
}
 }

void main()
  { 
     clrlcd();
     while(1)
     {
       displayon(); 
       setpage(0);
       setcolumn(0);
       lcddata(&ar0,8);
       delay() ; 

    setpage(1);
    setcolumn(0);
    lcddata(&ar1,8);
    delay() ; 

    setpage(2);
    setcolumn(0);
    lcddata(&ar2,8);
    delay() ; 

    setpage(3);
    setcolumn(0);
    lcddata(&ar3,8);
    delay() ; 

    setpage(4);
    setcolumn(0);
    lcddata(&ar4,8);
    delay() ; 

    setpage(5);
    setcolumn(0);
    lcddata(&ar5,8);
    delay() ; 

    setpage(6);
    setcolumn(0);
    lcddata(&ar6,8);
    delay() ; 

    setpage(7);
    setcolumn(0);
    lcddata(&ar7,8);
    delay() ; 

    setpage(0);
    setcolumn(64);
    lcddata(&ar00,5);
    delay() ; 

    setpage(1);
    setcolumn(64);
    lcddata(&ar11,5);
    delay() ; 

    setpage(2);
    setcolumn(64);
    lcddata(&ar22,5); 
    delay() ; 

    setpage(3);
    setcolumn(64);
    lcddata(&ar33,5);
    delay() ; 

    setpage(4);
    setcolumn(64);
    lcddata(&ar44,5);
    delay() ; 

    setpage(5);
    setcolumn(64);
    lcddata(&ar55,5);
    delay() ; 

    setpage(6);
    setcolumn(64);
    lcddata(&ar66,5);
    delay() ; 

    setpage(7);
    setcolumn(64);
    lcddata(&ar77,5);
    delay() ; 
} 
 }

I am having problem with this code as this is not running when i am trying to run it on proteus with a 128x64 glcd , i think the problem is with setpage function because when i try to access other page i cant . I tried different things with the setpage code but still it is not working . I have commented some sections where i am suspicious that the code might be wrong !!

\$\endgroup\$
4
  • \$\begingroup\$ I am not able to upload the image because i dont have enough rep but i will tell the problem , the chararcter are being printed at page 0 only , while i am expecting them to print on different pages \$\endgroup\$
    – abkds
    Commented Jun 16, 2013 at 4:43
  • \$\begingroup\$ I am quite sure that this question is not a good fit for this site where questions are meant to focus directly to electronics design. \$\endgroup\$ Commented Jun 16, 2013 at 11:06
  • \$\begingroup\$ Can you reduce your code to the smallest chunk that still has the problem? \$\endgroup\$ Commented Jun 16, 2013 at 12:17
  • \$\begingroup\$ @Scott Seidman Yes the setpage function is having the problem \$\endgroup\$
    – abkds
    Commented Jun 18, 2013 at 13:31

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.