How to print message on Graphical LCD

Thread Starter

@vajra

Joined May 2, 2018
154
Hello Friends

I learnt hardware interfacing of JHD12864E with AT89C51 Microcontroller in my previous thread. I flashed sample program into AT89c51. Sample program was working fine with GLCD. I am trying to print message on GLCD. I wrote program in c language without compiler error. When I flashed my program it's working with GLCD. I am sure about the all connection, it's look like correct because sample program is working with no problem.

I am thinking the problem is only in program code. I hope someone will help..
C:
#include<reg51.h>

#define GlcdDataBus  P2   //Data pins of GLCD connected to port P2

sbit RS  = P3^0;   // RS pin of GLCD connected to port P3.0
sbit RW  = P3^1;   // RW pin of GLCD connected to port P3.1
sbit EN  = P3^2;   //  E pin of GLCD connected to port P3.2 
sbit CS1 = P3^3;   // CS1 pin of GLCD connected to port P3.3
sbit CS2 = P3^4;   // CS2 pin of GLCD connected to port P3.4


/*function to generate Delay */
void Delay(int count)
{
    int i;
    for(i = 0; i < count; i++);
}

/* Function to send the command to LCD */
void Glcd_Command(char cmd)
{
    GlcdDataBus = cmd;    //Send the Command
    RS = 0;               // Send LOW pulse on RS pin for selecting Command register
    RW = 0;               // Send LOW pulse on RW pin for Write operation
    EN = 1;               // Generate a High-to-low pulse on EN pin
    Delay(100);
    EN = 0;
    Delay(1000);
}


/* Function to send the data to LCD */
void Glcd_Data(char dat)
{
    GlcdDataBus = dat;   //Send the data on DataBus
    RS = 1;              // Send HIGH pulse on RS pin for selecting data register
    RW = 0;              // Send LOW pulse on RW pin for Write operation
    EN = 1;              // Generate a High-to-low pulse on EN pin
    Delay(100);
    EN = 0;
    Delay(1000);
}

/*Function to send string to LCD*/
void GlcdData_String(unsigned char *string) 
{
  int index=0;
  
    while(string[index]!='\0')
  {
    Glcd_Data(string[index]);
    index++;
    Delay(10);
  }

}

void Glcd_SelectPage0() // CS1=1, CS2=0
{
    CS1 = 1;
    CS2 = 0;
}

void Glcd_SelectPage1() // CS1=0, CS1=1
{
    CS1 = 0;
    CS2 = 1;
}

void main(void)
{
  unsigned char message[] ="Hello World!";
   
      /* Select the Page0/Page1 and Turn on the GLCD */
    Glcd_SelectPage0();
    Glcd_Command(0x3f);
    Glcd_SelectPage1();
    Glcd_Command(0x3f);
    Delay(100);

    /* Select the Page0/Page1 and Enable the GLCD */
    Glcd_SelectPage0();
    Glcd_Command(0xc0);
    Glcd_SelectPage1();
    Glcd_Command(0xc0);
    Delay(100);
   
      Glcd_SelectPage0(); // Display HELLO World! on Page0, Line1
    Glcd_Command(0xb8);
      GlcdData_String(message);
}
 

jpanhalt

Joined Jan 18, 2008
11,087
How long is this delay?
upload_2018-6-7_6-15-38.png

The datasheet shows about 450 ns high is all that is required. I suspect Delay(100) is several times that period. Too long will still work, but it is not necessary.
 

Ian Rogers

Joined Dec 12, 2012
1,136
You need to add GLCD.C to your project and include it in you main C file.

#include "GLCD.H".. Make sure that both files are in the project directory..

If you want to know which functions to use, they are listed in the Header file, ( GLCD.h )
 

Thread Starter

@vajra

Joined May 2, 2018
154
You need to add GLCD.C to your project and include it in you main C file.

#include "GLCD.H".. Make sure that both files are in the project directory..

If you want to know which functions to use, they are listed in the Header file, ( GLCD.h )
Do you mean like this type ?

upload_2018-6-8_1-17-7.png
 
Last edited:

Thread Starter

@vajra

Joined May 2, 2018
154
I don't use Kiel, so I don't know where to put the files...Play with it and read the docs..
Okay.. I copied file glcd.c and glcd.h and pasted into there repective files as you can show in post #11.

Now the main.c is remaining What to do for further procedure ?
 

Ian Rogers

Joined Dec 12, 2012
1,136
I have been trying to run their library.... I'm struggling to get it working...

There are too many "special" things that have been written..... I suspect this library was ported from the GNU platform as the "systemUtils" library seems to convert functions.... Even when I transferred it all over, I still couldn't use it.

Give me a day or so and I'll clean it up!!
 

Thread Starter

@vajra

Joined May 2, 2018
154
I use SDCC not Keil, so there maybe a few mods.. Yes I used an AT89c52..
Okay. It's good to use header files and source file in project but I am struggling with it.

Can you help me to write whole program without using extra header file and extra source file like I was doing in my first post.
 

Ian Rogers

Joined Dec 12, 2012
1,136
Yes I can, however! You really need to know how to use multiple files, as when you move on it will be very necessary.

If you analyse this, you will see that it is exactly the same as before but all on one page.. A header is just to tell the compiler what to expect..

C:
#include <mcs51reg.h>
#define LcdDataBus  P2
#define LcdControlBus P0
#define RSL  P0_0 = 0
#define RSH  P0_0 = 1
#define RWL  P0_1 = 0
#define RWH  P0_1 = 1
#define ENL  P0_2 = 0
#define ENH  P0_2 = 1
#define CS1L  P0_3 = 0
#define CS1H P0_3 = 1
#define CS2L  P0_4 = 0
#define CS2H P0_4 = 1
#define DefaultDigits  10
#define GlcdFirstLine 0x00u
#define GlcdLastLine 0x07u
#define FirstLineAddress 0xB8
#define LastLineAddress  0xBF
#define BUSY_FLAG  7
void DELAY_us(int x);
void DELAY_ms(int x);
void GLCD_Init(void);
void GLCD_DisplayChar(unsigned char ch);
void GLCD_DisplayString(unsigned char  *);
void GLCD_ScrollMessage(unsigned char  lineNum, char *strptr);
void GLCD_Clear(void);
void GLCD_GoToPage(unsigned char  );
void GLCD_GoToLine(unsigned char  );
void GLCD_GoToNextLine(void);
void GLCD_SetCursor(unsigned char  lineNumber,unsigned char  CursorPosition);
void glcd_SelectPage0();
void glcd_SelectPage1();
void glcd_BusyCheck();
void glcd_CmdWrite( unsigned char  cmd);
void glcd_DataWrite( unsigned char  dat);
int GLCDPageNum;
int  GLCDLineNum;
int  GLCDCursorPos;

#define FONT_SIZE 5
const char GlcdFontTable[]=
{
0x00, 0x00, 0x00, 0x00, 0x00,  // space
0x00, 0x00, 0x2f, 0x00, 0x00,  // !
0x00, 0x07, 0x00, 0x07, 0x00,  // "
0x14, 0x7f, 0x14, 0x7f, 0x14,  // #
0x24, 0x2a, 0x7f, 0x2a, 0x12,  // $
0x23, 0x13, 0x08, 0x64, 0x62,  // %
0x36, 0x49, 0x55, 0x22, 0x50,  // &
0x00, 0x05, 0x03, 0x00, 0x00,  // '
0x00, 0x1c, 0x22, 0x41, 0x00,  // (
0x00, 0x41, 0x22, 0x1c, 0x00,  // )
0x14, 0x08, 0x3E, 0x08, 0x14,  // *
0x08, 0x08, 0x3E, 0x08, 0x08,  // +
0x00, 0x00, 0xA0, 0x60, 0x00,  // ,
0x08, 0x08, 0x08, 0x08, 0x08,  // -
0x00, 0x60, 0x60, 0x00, 0x00,  // .
0x20, 0x10, 0x08, 0x04, 0x02,  // /
0x3E, 0x51, 0x49, 0x45, 0x3E,  // 0
0x00, 0x42, 0x7F, 0x40, 0x00,  // 1
0x42, 0x61, 0x51, 0x49, 0x46,  // 2
0x21, 0x41, 0x45, 0x4B, 0x31,  // 3
0x18, 0x14, 0x12, 0x7F, 0x10,  // 4
0x27, 0x45, 0x45, 0x45, 0x39,  // 5
0x3C, 0x4A, 0x49, 0x49, 0x30,  // 6
0x01, 0x71, 0x09, 0x05, 0x03,  // 7
0x36, 0x49, 0x49, 0x49, 0x36,  // 8
0x06, 0x49, 0x49, 0x29, 0x1E,  // 9
0x00, 0x36, 0x36, 0x00, 0x00,  // :
0x00, 0x56, 0x36, 0x00, 0x00,  // ;
0x08, 0x14, 0x22, 0x41, 0x00,  // <
0x14, 0x14, 0x14, 0x14, 0x14,  // =
0x00, 0x41, 0x22, 0x14, 0x08,  // >
0x02, 0x01, 0x51, 0x09, 0x06,  // ?
0x32, 0x49, 0x59, 0x51, 0x3E,  // @
0x7C, 0x12, 0x11, 0x12, 0x7C,  // A
0x7F, 0x49, 0x49, 0x49, 0x36,  // B
0x3E, 0x41, 0x41, 0x41, 0x22,  // C
0x7F, 0x41, 0x41, 0x22, 0x1C,  // D
0x7F, 0x49, 0x49, 0x49, 0x41,  // E
0x7F, 0x09, 0x09, 0x09, 0x01,  // F
0x3E, 0x41, 0x49, 0x49, 0x7A,  // G
0x7F, 0x08, 0x08, 0x08, 0x7F,  // H
0x00, 0x41, 0x7F, 0x41, 0x00,  // I
0x20, 0x40, 0x41, 0x3F, 0x01,  // J
0x7F, 0x08, 0x14, 0x22, 0x41,  // K
0x7F, 0x40, 0x40, 0x40, 0x40,  // L
0x7F, 0x02, 0x0C, 0x02, 0x7F,  // M
0x7F, 0x04, 0x08, 0x10, 0x7F,  // N
0x3E, 0x41, 0x41, 0x41, 0x3E,  // O
0x7F, 0x09, 0x09, 0x09, 0x06,  // P
0x3E, 0x41, 0x51, 0x21, 0x5E,  // Q
0x7F, 0x09, 0x19, 0x29, 0x46,  // R
0x46, 0x49, 0x49, 0x49, 0x31,  // S
0x01, 0x01, 0x7F, 0x01, 0x01,  // T
0x3F, 0x40, 0x40, 0x40, 0x3F,  // U
0x1F, 0x20, 0x40, 0x20, 0x1F,  // V
0x3F, 0x40, 0x38, 0x40, 0x3F,  // W
0x63, 0x14, 0x08, 0x14, 0x63,  // X
0x07, 0x08, 0x70, 0x08, 0x07,  // Y
0x61, 0x51, 0x49, 0x45, 0x43,  // Z
0x00, 0x7F, 0x41, 0x41, 0x00,  // [
0x55, 0xAA, 0x55, 0xAA, 0x55,  // Backslash (Checker pattern)
0x00, 0x41, 0x41, 0x7F, 0x00,  // ]
0x04, 0x02, 0x01, 0x02, 0x04,  // ^
0x40, 0x40, 0x40, 0x40, 0x40,  // _
0x00, 0x03, 0x05, 0x00, 0x00,  // `
0x20, 0x54, 0x54, 0x54, 0x78,  // a
0x7F, 0x48, 0x44, 0x44, 0x38,  // b
0x38, 0x44, 0x44, 0x44, 0x20,  // c
0x38, 0x44, 0x44, 0x48, 0x7F,  // d
0x38, 0x54, 0x54, 0x54, 0x18,  // e
0x08, 0x7E, 0x09, 0x01, 0x02,  // f
0x18, 0xA4, 0xA4, 0xA4, 0x7C,  // g
0x7F, 0x08, 0x04, 0x04, 0x78,  // h
0x00, 0x44, 0x7D, 0x40, 0x00,  // i
0x40, 0x80, 0x84, 0x7D, 0x00,  // j
0x7F, 0x10, 0x28, 0x44, 0x00,  // k
0x00, 0x41, 0x7F, 0x40, 0x00,  // l
0x7C, 0x04, 0x18, 0x04, 0x78,  // m
0x7C, 0x08, 0x04, 0x04, 0x78,  // n
0x38, 0x44, 0x44, 0x44, 0x38,  // o
0xFC, 0x24, 0x24, 0x24, 0x18,  // p
0x18, 0x24, 0x24, 0x18, 0xFC,  // q
0x7C, 0x08, 0x04, 0x04, 0x08,  // r
0x48, 0x54, 0x54, 0x54, 0x20,  // s
0x04, 0x3F, 0x44, 0x40, 0x20,  // t
0x3C, 0x40, 0x40, 0x20, 0x7C,  // u
0x1C, 0x20, 0x40, 0x20, 0x1C,  // v
0x3C, 0x40, 0x30, 0x40, 0x3C,  // w
0x44, 0x28, 0x10, 0x28, 0x44,  // x
0x1C, 0xA0, 0xA0, 0xA0, 0x7C,  // y
0x44, 0x64, 0x54, 0x4C, 0x44,  // z
0x00, 0x10, 0x7C, 0x82, 0x00,  // {
0x00, 0x00, 0xFF, 0x00, 0x00,  // |
0x00, 0x82, 0x7C, 0x10, 0x00,  // }
0x00, 0x06, 0x09, 0x09, 0x06  // ~ (Degrees)
};
void DELAY_us(int x)
 {
 x>>=3;
 while(x--);
 }
void DELAY_ms(int x)
 {
 while(x--)
 DELAY_us(1000);
 }
void GLCD_Init()
{
 /* Select the Page0/Page1 and Enable the GLCD */
 glcd_SelectPage0();
 glcd_CmdWrite(0x3f);
 glcd_SelectPage1();
 glcd_CmdWrite(0x3f);
 DELAY_ms(10);
 /* Select the Page0/Page1 and Enable the GLCD */
 glcd_SelectPage0();
 glcd_CmdWrite(0xc0);
 glcd_SelectPage1();
 glcd_CmdWrite(0xc0);
 GLCD_GoToPage(0);
 /* Clear the complete LCD during init */
 GLCD_Clear();
 /* Set the cursor to beginning of page0 */
 GLCDPageNum=0;
 GLCDLineNum=0xB8;
 GLCDCursorPos=0x40;
 GLCD_GoToPage(0);
}
void GLCD_DisplayChar(unsigned char ch)
{
 unsigned char  dat,i=0;
 int addr = 0;
 if(((GLCDPageNum == 0x01) && ((GLCDCursorPos+FONT_SIZE)>=128)) || (ch=='\n'))
 {
 /* If the cursor has reached to end of line on page1
 OR NewLine command is issued Then Move the cursor to next line */
 GLCD_GoToNextLine();
 }
 if(ch!='\n') /* TODO */
 {
 ch -= 0x20; // As the lookup table starts from Space(0x20)
 addr = ch * 5;
 while(1)
 {
 if((GLCDPageNum == 0x00) && (GLCDCursorPos==0x80))
 {
 /* If the cursor has reached to end of line on page0
  Then Move the cursor to Page1 */
 GLCD_GoToPage(1);
 }
 dat= GlcdFontTable[addr+i]; /* Get the data to be displayed for LookUptable*/
 i++;
 glcd_DataWrite(dat); /* Display the data and keep track of cursor */
 GLCDCursorPos++;

 if(i==FONT_SIZE) /* Exit the loop if End of char is encountered */
 {
 glcd_DataWrite(0x00); /* Display the data and keep track of cursor */
 GLCDCursorPos++;
 break;
 }
 }
 }
}
void GLCD_DisplayString(unsigned char  *ptr)
{
 while(*ptr)
 GLCD_DisplayChar(*ptr++);
}
void GLCD_ScrollMessage(unsigned char  lineNum, char *strptr)
{
 unsigned char i,j,k,l,cursor,ch;
 if(lineNum > 7)
 lineNum = 0; // Select first line if the var_lineNumber_u8 is out of range
 for(i=0;strptr[i];i++)
 {
 /* Loop to display the complete string,  each time 16 chars are displayed and
  pointer is incremented to point to next char */
 for(k=0;k<6;k++)
 {
 GLCD_SetCursor(lineNum,6-k);  //Move the Cursor to first line
 cursor = 6-k;
 
 for(j=0;strptr[i+j] && (cursor<128);j++)
 {
 ch = strptr[i+j]-0x20;
 for(l=0;(l<5) && (cursor<128);l++)//Display first 16 Chars or till Null char is reached
 {
  glcd_DataWrite(GlcdFontTable[ch+l]);
 cursor++;
    if(cursor==64)  /* Has the cursor reached end of page0 */
  {
    glcd_SelectPage1(); /*  then set it to beginning of page1 */
 glcd_CmdWrite(FirstLineAddress+lineNum); 
    glcd_CmdWrite(0x40); 
 
   } 
 } 
 
  glcd_DataWrite(0);
 cursor++;
    if(cursor==64)  /* Has the cursor reached end of page0 */
  {
    glcd_SelectPage1(); /*  then set it to beginning of page1 */
 glcd_CmdWrite(FirstLineAddress+lineNum); 
    glcd_CmdWrite(0x40); 
 
   } 
 }
 
 while(cursor < 128)
 {
 DELAY_us(10);
 cursor++;
 }
 DELAY_ms(20);
 }
 }
} 

void GLCD_Clear()
{
 unsigned char  line,cursor;
 for(line=0;line<8;line++)  /* loop through all the 8lines to clear the display */
 {
 glcd_SelectPage0();  /* Select page0 and set the cursor to first position */
 glcd_CmdWrite(0x40);
 glcd_CmdWrite(FirstLineAddress+line);
 for(cursor=0;cursor<128;cursor++) /* Clear all the 128 pixels of selected line */
 {
 if(cursor==64)  /* Has the cursor reached end of page0 */
 {
 glcd_SelectPage1(); /*  then set it to beginning of page1 */
 glcd_CmdWrite(0x40);
 glcd_CmdWrite(FirstLineAddress+line);
 }
 glcd_DataWrite(0x00); /* Clear each pixel by displaying blank */
 }
 }
 GLCD_GoToLine(0);
}
void GLCD_GoToPage(unsigned char  pageNumber)
{
 if((pageNumber==0) || (pageNumber ==1))
 { /* for 128/64 GLCD only page 0&1 are supported.
 Select the specified page and move the cursor accordingly */
 if(pageNumber == 0)
 {
 glcd_SelectPage0();
 }
 else
 {
 glcd_SelectPage1();
 }
 GLCDPageNum=pageNumber;
 GLCDCursorPos=0x40;
 glcd_CmdWrite(GLCDLineNum);
 glcd_CmdWrite(GLCDCursorPos);
 }
}
void  GLCD_GoToLine(unsigned char  lineNumber)
{
 if(lineNumber<8)
 {  /* If the line number is within range
  then move it to specified line on page0 and keep track*/
 GLCDLineNum = lineNumber+FirstLineAddress;
 GLCD_GoToPage(0);
 }
}
void  GLCD_GoToNextLine()
{
 /*Increment the current line number.
  In case it exceeds the limit, rool it back to first line */
 GLCDLineNum++;
 if(GLCDLineNum > LastLineAddress)
 GLCDLineNum = FirstLineAddress;
 GLCD_GoToPage(0); /* Finally move it to next line on page0 */
}

void GLCD_SetCursor(unsigned char  lineNumber,unsigned char  CursorPosition)
{
 unsigned char  pageNumber;
 if(((lineNumber >=0x00)  && (lineNumber <= GlcdLastLine))
 && ((CursorPosition>=0x00) && (CursorPosition <= 128)) )
 {
 pageNumber = CursorPosition / 64; //Divide the cursor pos by 64 to get the page
 CursorPosition = CursorPosition % 0x3f; // Cusror pos should be within 64(0x3f),
 if(pageNumber==0x00)  /* Check for page number and set accordingly */
 {
 glcd_SelectPage0();
 }
 else
 {
 glcd_SelectPage1();
 }
 GLCDPageNum = pageNumber; /* Keep the track of page selected */
 GLCDLineNum=lineNumber | FirstLineAddress; /* Select the specified line number */
 GLCDCursorPos=CursorPosition |0x40; /* Select the specified cursor position */
 glcd_CmdWrite(GLCDCursorPos); /* Command the LCD to move to specified page,line,cursor*/
 glcd_CmdWrite(GLCDLineNum);
 }
}
void glcd_CmdWrite( unsigned char cmd)
 {
 glcd_BusyCheck();
 LcdDataBus = cmd ;
 RSL; // Select the Data Register by pulling RS LOW
 RWL;  // Select the Write operation by pulling RW LOW
 ENL;  // Send a High-to-Low Pulse at Enable Pin
 DELAY_us(1);
 ENH;
 }
void glcd_DataWrite(unsigned char dat)
 {
 glcd_BusyCheck();
 LcdDataBus = dat;
 RSH; // Select the Data Register by pulling RS LOW
 RWL;   // Select the Write operation by pulling RW LOW
 ENL;  // Send a High-to-Low Pulse at Enable Pin
 DELAY_us(1);
 ENH;
 }
void glcd_SelectPage0()
 {
 CS1H;
 CS2L;
 }
void glcd_SelectPage1()
 {
 CS1L;
 CS2H;
 }
void glcd_BusyCheck()
 { 
 DELAY_us(100);
 }
void main(void)
 {
 GLCD_Init();
 GLCD_Clear();
 GLCD_DisplayString("Hello world!!!");
 while(1);
 
 }
 

Thread Starter

@vajra

Joined May 2, 2018
154
Yes I can, however! You really need to know how to use multiple files, as when you move on it will be very necessary.

If you analyse this, you will see that it is exactly the same as before but all on one page.. A header is just to tell the compiler what to expect..
This code give me so much errors

I did changes and tried to run but still struggling with it
C:
#include <reg51.h>
#define LcdDataBus  P2
#define LcdControlBus P0
#define RSL  P0^0 = 0
#define RSH  P0^0 = 1
#define RWL  P0^1 = 0
#define RWH  P0^1 = 1
#define ENL  P0^2 = 0
#define ENH  P0^2 = 1
#define CS1L  P0^3 = 0
#define CS1H P0^3 = 1
#define CS2L  P0^4 = 0
#define CS2H P0^4 = 1
#define DefaultDigits  10
#define GlcdFirstLine 0x00u
#define GlcdLastLine 0x07u
#define FirstLineAddress 0xB8
#define LastLineAddress  0xBF
#define BUSY_FLAG  7
void DELAY_us(int x);
void DELAY_ms(int x);
void GLCD_Init(void);
void GLCD_DisplayChar(unsigned char ch);
void GLCD_DisplayString(unsigned char  *);
void GLCD_ScrollMessage(unsigned char  lineNum, char *strptr);
void GLCD_Clear(void);
void GLCD_GoToPage(unsigned char  );
void GLCD_GoToLine(unsigned char  );
void GLCD_GoToNextLine(void);
void GLCD_SetCursor(unsigned char  lineNumber,unsigned char  CursorPosition);
void glcd_SelectPage0();
void glcd_SelectPage1();
void glcd_BusyCheck();
void glcd_CmdWrite( unsigned char  cmd);
void glcd_DataWrite( unsigned char  dat);
int GLCDPageNum;
int  GLCDLineNum;
int  GLCDCursorPos;
#define FONT_SIZE 5
const char GlcdFontTable[]=
{
0x00, 0x00, 0x00, 0x00, 0x00,  // space
0x00, 0x00, 0x2f, 0x00, 0x00,  // !
0x00, 0x07, 0x00, 0x07, 0x00,  // "
0x14, 0x7f, 0x14, 0x7f, 0x14,  // #
0x24, 0x2a, 0x7f, 0x2a, 0x12,  // $
0x23, 0x13, 0x08, 0x64, 0x62,  // %
0x36, 0x49, 0x55, 0x22, 0x50,  // &
0x00, 0x05, 0x03, 0x00, 0x00,  // '
0x00, 0x1c, 0x22, 0x41, 0x00,  // (
0x00, 0x41, 0x22, 0x1c, 0x00,  // )
0x14, 0x08, 0x3E, 0x08, 0x14,  // *
0x08, 0x08, 0x3E, 0x08, 0x08,  // +
0x00, 0x00, 0xA0, 0x60, 0x00,  // ,
0x08, 0x08, 0x08, 0x08, 0x08,  // -
0x00, 0x60, 0x60, 0x00, 0x00,  // .
0x20, 0x10, 0x08, 0x04, 0x02,  // /
0x3E, 0x51, 0x49, 0x45, 0x3E,  // 0
0x00, 0x42, 0x7F, 0x40, 0x00,  // 1
0x42, 0x61, 0x51, 0x49, 0x46,  // 2
0x21, 0x41, 0x45, 0x4B, 0x31,  // 3
0x18, 0x14, 0x12, 0x7F, 0x10,  // 4
0x27, 0x45, 0x45, 0x45, 0x39,  // 5
0x3C, 0x4A, 0x49, 0x49, 0x30,  // 6
0x01, 0x71, 0x09, 0x05, 0x03,  // 7
0x36, 0x49, 0x49, 0x49, 0x36,  // 8
0x06, 0x49, 0x49, 0x29, 0x1E,  // 9
0x00, 0x36, 0x36, 0x00, 0x00,  // :
0x00, 0x56, 0x36, 0x00, 0x00,  // ;
0x08, 0x14, 0x22, 0x41, 0x00,  // <
0x14, 0x14, 0x14, 0x14, 0x14,  // =
0x00, 0x41, 0x22, 0x14, 0x08,  // >
0x02, 0x01, 0x51, 0x09, 0x06,  // ?
0x32, 0x49, 0x59, 0x51, 0x3E,  // @
0x7C, 0x12, 0x11, 0x12, 0x7C,  // A
0x7F, 0x49, 0x49, 0x49, 0x36,  // B
0x3E, 0x41, 0x41, 0x41, 0x22,  // C
0x7F, 0x41, 0x41, 0x22, 0x1C,  // D
0x7F, 0x49, 0x49, 0x49, 0x41,  // E
0x7F, 0x09, 0x09, 0x09, 0x01,  // F
0x3E, 0x41, 0x49, 0x49, 0x7A,  // G
0x7F, 0x08, 0x08, 0x08, 0x7F,  // H
0x00, 0x41, 0x7F, 0x41, 0x00,  // I
0x20, 0x40, 0x41, 0x3F, 0x01,  // J
0x7F, 0x08, 0x14, 0x22, 0x41,  // K
0x7F, 0x40, 0x40, 0x40, 0x40,  // L
0x7F, 0x02, 0x0C, 0x02, 0x7F,  // M
0x7F, 0x04, 0x08, 0x10, 0x7F,  // N
0x3E, 0x41, 0x41, 0x41, 0x3E,  // O
0x7F, 0x09, 0x09, 0x09, 0x06,  // P
0x3E, 0x41, 0x51, 0x21, 0x5E,  // Q
0x7F, 0x09, 0x19, 0x29, 0x46,  // R
0x46, 0x49, 0x49, 0x49, 0x31,  // S
0x01, 0x01, 0x7F, 0x01, 0x01,  // T
0x3F, 0x40, 0x40, 0x40, 0x3F,  // U
0x1F, 0x20, 0x40, 0x20, 0x1F,  // V
0x3F, 0x40, 0x38, 0x40, 0x3F,  // W
0x63, 0x14, 0x08, 0x14, 0x63,  // X
0x07, 0x08, 0x70, 0x08, 0x07,  // Y
0x61, 0x51, 0x49, 0x45, 0x43,  // Z
0x00, 0x7F, 0x41, 0x41, 0x00,  // [
0x55, 0xAA, 0x55, 0xAA, 0x55,  // Backslash (Checker pattern)
0x00, 0x41, 0x41, 0x7F, 0x00,  // ]
0x04, 0x02, 0x01, 0x02, 0x04,  // ^
0x40, 0x40, 0x40, 0x40, 0x40,  // _
0x00, 0x03, 0x05, 0x00, 0x00,  // `
0x20, 0x54, 0x54, 0x54, 0x78,  // a
0x7F, 0x48, 0x44, 0x44, 0x38,  // b
0x38, 0x44, 0x44, 0x44, 0x20,  // c
0x38, 0x44, 0x44, 0x48, 0x7F,  // d
0x38, 0x54, 0x54, 0x54, 0x18,  // e
0x08, 0x7E, 0x09, 0x01, 0x02,  // f
0x18, 0xA4, 0xA4, 0xA4, 0x7C,  // g
0x7F, 0x08, 0x04, 0x04, 0x78,  // h
0x00, 0x44, 0x7D, 0x40, 0x00,  // i
0x40, 0x80, 0x84, 0x7D, 0x00,  // j
0x7F, 0x10, 0x28, 0x44, 0x00,  // k
0x00, 0x41, 0x7F, 0x40, 0x00,  // l
0x7C, 0x04, 0x18, 0x04, 0x78,  // m
0x7C, 0x08, 0x04, 0x04, 0x78,  // n
0x38, 0x44, 0x44, 0x44, 0x38,  // o
0xFC, 0x24, 0x24, 0x24, 0x18,  // p
0x18, 0x24, 0x24, 0x18, 0xFC,  // q
0x7C, 0x08, 0x04, 0x04, 0x08,  // r
0x48, 0x54, 0x54, 0x54, 0x20,  // s
0x04, 0x3F, 0x44, 0x40, 0x20,  // t
0x3C, 0x40, 0x40, 0x20, 0x7C,  // u
0x1C, 0x20, 0x40, 0x20, 0x1C,  // v
0x3C, 0x40, 0x30, 0x40, 0x3C,  // w
0x44, 0x28, 0x10, 0x28, 0x44,  // x
0x1C, 0xA0, 0xA0, 0xA0, 0x7C,  // y
0x44, 0x64, 0x54, 0x4C, 0x44,  // z
0x00, 0x10, 0x7C, 0x82, 0x00,  // {
0x00, 0x00, 0xFF, 0x00, 0x00,  // |
0x00, 0x82, 0x7C, 0x10, 0x00,  // }
0x00, 0x06, 0x09, 0x09, 0x06  // ~ (Degrees)
};
void DELAY_us(int x)
{
x>>=3;
while(x--);
}
void DELAY_ms(int x)
{
while(x--)
DELAY_us(1000);
}
void GLCD_Init()
{
/* Select the Page0/Page1 and Enable the GLCD */
glcd_SelectPage0();
glcd_CmdWrite(0x3f);
glcd_SelectPage1();
glcd_CmdWrite(0x3f);
DELAY_ms(10);
/* Select the Page0/Page1 and Enable the GLCD */
glcd_SelectPage0();
glcd_CmdWrite(0xc0);
glcd_SelectPage1();
glcd_CmdWrite(0xc0);
GLCD_GoToPage(0);
/* Clear the complete LCD during init */
GLCD_Clear();
/* Set the cursor to beginning of page0 */
GLCDPageNum=0;
GLCDLineNum=0xB8;
GLCDCursorPos=0x40;
GLCD_GoToPage(0);
}
void GLCD_DisplayChar(unsigned char ch)
{
unsigned char  dat,i=0;
int addr = 0;
if(((GLCDPageNum == 0x01) && ((GLCDCursorPos+FONT_SIZE)>=128)) || (ch=='\n'))
{
/* If the cursor has reached to end of line on page1
OR NewLine command is issued Then Move the cursor to next line */
GLCD_GoToNextLine();
}
if(ch!='\n') /* TODO */
{
ch -= 0x20; // As the lookup table starts from Space(0x20)
addr = ch * 5;
while(1)
{
if((GLCDPageNum == 0x00) && (GLCDCursorPos==0x80))
{
/* If the cursor has reached to end of line on page0
  Then Move the cursor to Page1 */
GLCD_GoToPage(1);
}
dat= GlcdFontTable[addr+i]; /* Get the data to be displayed for LookUptable*/
i++;
glcd_DataWrite(dat); /* Display the data and keep track of cursor */
GLCDCursorPos++;
if(i==FONT_SIZE) /* Exit the loop if End of char is encountered */
{
glcd_DataWrite(0x00); /* Display the data and keep track of cursor */
GLCDCursorPos++;
break;
}
}
}
}
void GLCD_DisplayString(unsigned char  *ptr)
{
while(*ptr)
GLCD_DisplayChar(*ptr++);
}
void GLCD_ScrollMessage(unsigned char  lineNum, char *strptr)
{
unsigned char i,j,k,l,cursor,ch;
if(lineNum > 7)
lineNum = 0; // Select first line if the var_lineNumber_u8 is out of range
for(i=0;strptr[i];i++)
{
/* Loop to display the complete string,  each time 16 chars are displayed and
  pointer is incremented to point to next char */
for(k=0;k<6;k++)
{
GLCD_SetCursor(lineNum,6-k);  //Move the Cursor to first line
cursor = 6-k;
for(j=0;strptr[i+j] && (cursor<128);j++)
{
ch = strptr[i+j]-0x20;
for(l=0;(l<5) && (cursor<128);l++)//Display first 16 Chars or till Null char is reached
{
  glcd_DataWrite(GlcdFontTable[ch+l]);
cursor++;
    if(cursor==64)  /* Has the cursor reached end of page0 */
  {
    glcd_SelectPage1(); /*  then set it to beginning of page1 */
glcd_CmdWrite(FirstLineAddress+lineNum);
    glcd_CmdWrite(0x40);
   }
}
  glcd_DataWrite(0);
cursor++;
    if(cursor==64)  /* Has the cursor reached end of page0 */
  {
    glcd_SelectPage1(); /*  then set it to beginning of page1 */
glcd_CmdWrite(FirstLineAddress+lineNum);
    glcd_CmdWrite(0x40);
   }
}
while(cursor < 128)
{
DELAY_us(10);
cursor++;
}
DELAY_ms(20);
}
}
}
void GLCD_Clear()
{
unsigned char  line,cursor;
for(line=0;line<8;line++)  /* loop through all the 8lines to clear the display */
{
glcd_SelectPage0();  /* Select page0 and set the cursor to first position */
glcd_CmdWrite(0x40);
glcd_CmdWrite(FirstLineAddress+line);
for(cursor=0;cursor<128;cursor++) /* Clear all the 128 pixels of selected line */
{
if(cursor==64)  /* Has the cursor reached end of page0 */
{
glcd_SelectPage1(); /*  then set it to beginning of page1 */
glcd_CmdWrite(0x40);
glcd_CmdWrite(FirstLineAddress+line);
}
glcd_DataWrite(0x00); /* Clear each pixel by displaying blank */
}
}
GLCD_GoToLine(0);
}
void GLCD_GoToPage(unsigned char  pageNumber)
{
if((pageNumber==0) || (pageNumber ==1))
{ /* for 128/64 GLCD only page 0&1 are supported.
Select the specified page and move the cursor accordingly */
if(pageNumber == 0)
{
glcd_SelectPage0();
}
else
{
glcd_SelectPage1();
}
GLCDPageNum=pageNumber;
GLCDCursorPos=0x40;
glcd_CmdWrite(GLCDLineNum);
glcd_CmdWrite(GLCDCursorPos);
}
}
void  GLCD_GoToLine(unsigned char  lineNumber)
{
if(lineNumber<8)
{  /* If the line number is within range
  then move it to specified line on page0 and keep track*/
GLCDLineNum = lineNumber+FirstLineAddress;
GLCD_GoToPage(0);
}
}
void  GLCD_GoToNextLine()
{
/*Increment the current line number.
  In case it exceeds the limit, rool it back to first line */
GLCDLineNum++;
if(GLCDLineNum > LastLineAddress)
GLCDLineNum = FirstLineAddress;
GLCD_GoToPage(0); /* Finally move it to next line on page0 */
}
void GLCD_SetCursor(unsigned char  lineNumber,unsigned char  CursorPosition)
{
unsigned char  pageNumber;
if(((lineNumber >=0x00)  && (lineNumber <= GlcdLastLine))
&& ((CursorPosition>=0x00) && (CursorPosition <= 128)) )
{
pageNumber = CursorPosition / 64; //Divide the cursor pos by 64 to get the page
CursorPosition = CursorPosition % 0x3f; // Cusror pos should be within 64(0x3f),
if(pageNumber==0x00)  /* Check for page number and set accordingly */
{
glcd_SelectPage0();
}
else
{
glcd_SelectPage1();
}
GLCDPageNum = pageNumber; /* Keep the track of page selected */
GLCDLineNum=lineNumber | FirstLineAddress; /* Select the specified line number */
GLCDCursorPos=CursorPosition |0x40; /* Select the specified cursor position */
glcd_CmdWrite(GLCDCursorPos); /* Command the LCD to move to specified page,line,cursor*/
glcd_CmdWrite(GLCDLineNum);
}
}
void glcd_CmdWrite( unsigned char cmd)
{
glcd_BusyCheck();
LcdDataBus = cmd ;
RSL; // Select the Data Register by pulling RS LOW
RWL;  // Select the Write operation by pulling RW LOW
ENL;  // Send a High-to-Low Pulse at Enable Pin
DELAY_us(1);
ENH;
}
void glcd_DataWrite(unsigned char dat)
{
glcd_BusyCheck();
LcdDataBus = dat;
RSH; // Select the Data Register by pulling RS LOW
RWL;   // Select the Write operation by pulling RW LOW
ENL;  // Send a High-to-Low Pulse at Enable Pin
DELAY_us(1);
ENH;
}
void glcd_SelectPage0()
{
CS1H;
CS2L;
}
void glcd_SelectPage1()
{
CS1L;
CS2H;
}
void glcd_BusyCheck()
{
DELAY_us(100);
}
void main(void)
{
GLCD_Init();
GLCD_Clear();
GLCD_DisplayString("Hello world!!!");
while(1);
}
I am getting following errors
compiling lcd.c...
lcd.c(340): error C141: syntax error near '='
lcd.c(341): error C141: syntax error near '='
lcd.c(342): error C141: syntax error near '='
lcd.c(344): error C141: syntax error near '='
lcd.c(350): error C141: syntax error near '='
lcd.c(351): error C141: syntax error near '='
lcd.c(352): error C141: syntax error near '='
lcd.c(354): error C141: syntax error near '='
lcd.c(358): error C141: syntax error near '='
lcd.c(359): error C141: syntax error near '='
lcd.c(363): error C141: syntax error near '='
lcd.c(364): error C141: syntax error near '='
lcd.c - 12 Error(s), 0 Warning(s).

if I write line 340 as RSL= 0; it also give error
 
Last edited:
Top