LPC 2148 Interfacing with GLCD

Interfacing KS0108 based 128×64 Graphical LCD with LPC2148


Interfacing Diagram

glcd-interfacing-with-lpc2148


Algorithm


  1. Start
  2. Initially define hardware of interfacing Diagram 
  3. Initialize GLCD by selecting functions of LPC2148 pins as GPIO, Set direction of pins as an output pins, Send Commands to GLCD to Turn on both halves of GLCD, Set Y-address (Column), Set X-address (Page), Set Z-address(Start of line)
  4. Call function GLCD_Clear_all. If column no. is <64 Turn on left half of display else turn on Right half.Send Commands to GLCD through command function to  Set Y-address (Column), Set X-address (Page). First Send zero (0) data to GLCD to clear left half display first and then second half.
  5. GLCD Command function:- Clear command value available on data pins first ,shift the command value by 16 bits to left side to get available on P0.16 to P0.23 , Make RS pin=0, High to low pulse on Enable pin
  6. GLCD Data function :- Clear data available on data pins first ,shift the data by 16 bits to left side to get available on P0.16 to P0.23 , Make RS pin=1, High to low pulse on Enable pin
  7. Call GLCD_String function and which is same of GLCD_Clear_All function and display image which is stored in Image array of Image.h file
  8. End

Embedded C Program



/**************************************************************************/
/* Project Name:- Graphics LCD Interfacing with LPC2148      */
/* Device:- LPC2148                          */
/* Compiler:- KeilUvision4                   */
/* Language:- Embedded  C*/
/* Visit www.wikinote.org for more Details   */
/********************************************************************************************/
-------------------------------------------------------------
P0.16-P0.23 =>LCD data lines
P0.8-RS,P0.12-EN,P0.13-CS1,P0.14-CS2,P0.15-RW
J11-J1,J9-J2
/*************************************************************/

#include  
#include "Image.h"

#define LCD_D0  1<<16
#define LCD_D1  1<<17
#define LCD_D2  1<<18
#define LCD_D3  1<<19
#define LCD_D4  1<<20
#define LCD_D5  1<<21
#define LCD_D6  1<<22
#define LCD_D7  1<<23
#define RS (1<<8)
#define RW (1<<15)
#define EN  (1<<12) 
#define CS1  (1<<13)                  
#define CS2  (1<<14) 
#define TotalPage   8

void delay(int k) ;

void GLCD_Command(int Command)  /* GLCD command function */
{
 IOCLR0= (LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7);
 Command = Command<<16;
 IOSET0 = Command;  /* Copy command on data pin */
 IOCLR0 = RS; /* Make RS LOW to select command register */
 IOCLR0 = RW;   /* Make RW LOW to select write operation */
 IOSET0 = EN;/* Make HIGH to LOW transition on Enable pin */
 delay(5);
 IOCLR0 = EN;
}

void GLCD_Data(int Data)  /* GLCD data function */
{
 IOCLR0= (LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7);
 Data = Data << 16;
 IOSET0 = Data;  /* Copy data on data pin */
 IOSET0 = RS; /* Make RS HIGH to select data register */
 IOCLR0 = RW; /* Make RW LOW to select write operation */
 IOSET0 = EN;/* Make HIGH to LOW transition on Enable pin */
 delay(5);
 IOCLR0 = EN;
}

void GLCD_Init()   /* GLCD initialize function */
{
 PINSEL0=0x00000000;
 PINSEL1=0x00000000;
 IODIR0= (LCD_D0|LCD_D1|LCD_D2|LCD_D3|LCD_D4|LCD_D5|LCD_D6|LCD_D7|RS|RW|EN|CS1|CS2);
/* Select both left & right half of display */
 IOSET0 = (CS1 | CS2);
 delay(20);     
 GLCD_Command(0x3E);    /* Display OFF */
 GLCD_Command(0x40);    /* Set Y address (column=0) */
 GLCD_Command(0xB8);    /* Set x address (page=0) */
 GLCD_Command(0xC0);  /* Set z address (start line=0) */
 GLCD_Command(0x3F);    /* Display ON */
}

void GLCD_ClearAll()    /* GLCD all display clear function */
{
int column,page;
   
for(page=0;page<8;page++)  /* Print 16 pages i.e. 8 page of each half of display */
 {
  IOSET0 = CS1; /* If yes then change segment controller */
  IOCLR0 = CS2;
  GLCD_Command(0x40);    /* Set Y address (column=0) */
     GLCD_Command((0xB8+page));/* Increment page address */
 for(column=0;column<128;column++)
  {
  if (column == 64)
   {
   IOCLR0 = CS1; /* If yes then change segment controller */
      IOSET0 = CS2; 
   GLCD_Command(0x40);    /* Set Y address (column=0) */
       GLCD_Command((0xB8+page));/* Increment page address */
   }
     GLCD_Data(0);  /* Print 64 column of each page */
  }
 }
}

void GLCD_String(const char *image) /* GLCD string write function */
{
int column,page;
   
for(page=0;page<8;page++)  /* Print 16 pages i.e. 8 page of each half of display */
 {
  IOSET0 = CS1; /* If yes then change segment controller */
  IOCLR0 = CS2;
  GLCD_Command(0x40);    /* Set Y address (column=0) */
     GLCD_Command((0xB8+page));/* Increment page address */
 for(column=0;column<128;column++)
  {
  if (column == 64)
   {
   IOCLR0 = CS1; /* If yes then change segment controller */
      IOSET0 = CS2;
   GLCD_Command(0x40);    /* Set Y address (column=0) */
       GLCD_Command((0xB8+page));/* Increment page address */
   }
     GLCD_Data(*image++);  /* Print 64 column of each page */
  }
 }
}
// LCD Delay Function
void delay(int k)  
{
 int a,b;
 for(a=0;a<=k;a++)
 for(b=0;b<100;b++);
}

int main(void)
{
 GLCD_Init();     /* Initialize GLCD */
 GLCD_ClearAll();    /* Clear all GLCD display */
 GLCD_String(img);     /* Display image on GLCD display */
 while(1);
}
Download GLCD Project : Click Here

Video Tutorial Plus Keil Simulation Plus Hardware Output



GLCD Program for Square Waveform Generation

GLCD Output



void main()
{
int x=16; ///initial position
int y=16; ///initial position
for (x=16;x<=20;x++)
{
Pixel(x,y);   ///1st line x=16 to x=20 and y=16 fix
}
for (y=16;y<=20;y++)
{
Pixel(x,y); ///2nd line y=16 to y=20 and x=20 fix
}
for (x=20;x<=16;x--)
{
Pixel(x,y); ///3rd  line x=20 to x=16 and y=20 fix
}
for (y=20;y<=24;y++)
{
Pixel(x,y); ///4th line y=20 to y=24 and x=16 fix
}
for (x=16;x<=20;x++)
{
Pixel(x,y);   ///5th line x=16 to x=20 and y=24 fix
}
}
                    
Note- Here I have called Pixel Function and I am considering x and y as its elements

References

  • Notes by Prof S.S. Kendre, Edited by Prof Sujit Wagh, Sinhgad's SKNCOE, Pune
  • WikiNote Foundation

Last modified: Monday, 10 February 2020, 3:54 PM