LPC2148 Interfacing with LCD

LCD Interfacing with LPC2148


Introduction to LCD


The LCDs have a parallel interface, meaning that the microcontroller has to manipulate several interface pins at once to control the display. The interface consists of the following pins:

LCD Pin Description

LCD pin no. LCD pin name LCD pin Description
1 Vss Ground pin of the LCD module.
2 Vcc Power to LCD module (+5V supply)
3 VEE Contrast adjustment pin
4 RS Register select pin
RS=0 command register.
RS=1 data register. 
5 R/W Read/Write modes
R/W=1; Read mode
R/W=1; Write mode
6 EN This pin is meant for enabling the LCD module
7-14 DB0 to DB7 8 data pins
15 LED+ Anode of the back light LED
16 LED- Cathode of the back light LED

The process of controlling the display involves putting the data that form the image of what you want to display into the data registers, then putting instructions in the instruction register. 

Mostly used commands or instructions for LCD
Sr.No. Instruction Hex
1 Function Set: 8-bit mode, 1 Line, 5x7 Dots matrix for each character display 0x30
2 Function Set: 8-bit mode, 2 Line, 5x7 Dots matrix for each character display 0x38
3 Function Set: 4-bit mode, 1 Line, 5x7 Dots matrix for each character display 0x20
4 Function Set: 4-bit mode, 2 Line, 5x7 Dots matrix for each character display 0x28
5 Clear display screen 0x01
6 Return Home 0x02
7 Decrement cursor(Shift to left) 0x04
8 Increment cursor(Shift to Right) 0x06
9 Display off Cursor off 0x08
10 Display on Cursor on 0x0E
11 Display on Cursor off 0x0C
12 Display on Cursor blinking 0x0F
13 Shift entire display left 0x18
14 Shift entire display right 0x1C
15 Move cursor left by one character 0x10
16 Move cursor right by one character 0x14
17 Clear Display (also clear DDRAM content) 0x01
18 Force cursor position on  first position of  first  0x80 
19 Force cursor position on  first position of  second row  0xC0 

Schematic Diagram

LCD



Interfacing Description


LPC2148 Port Pin No. LCD Pins
P1.16 D0
P1.17 D1
P1.18 D2
P1.19 D3
P1.20 D4
P1.21 D5
P1.22 D6
P1.23 D7
P1.25 RS
P0.29 EN
P0.10 BC

Embedded C code for the Interfacing

/**************************************************************************/

/* Project Name:- 16x2 LCD Interfacing with LPC2148      */

/* Device:- LPC2148                          */

/* Compiler:- KeilUvision4                   */

/* Language:- Embedded C  */

/* Visit www.wikinote.org for more Details   */

/********************************************************************************************

#include<lpc21xx.h>

void lcdcmd(unsigned int cmd);

void lcddata(unsigned int data);

void delay(unsigned int itime);

int main()

  unsigned char array[]="WIKINOTE FOUNDATION";

  unsigned int i=0;

  PINSEL0=0X00000000;

  PINSEL1=0X00000000;

  PINSEL2=0X00000000;

  IODIR0=0X20000400;

  IODIR1=0X02FF0000;

  IOCLR0=0X00000400;

  lcdcmd(0x38);  //16x2 LCD in 8-bit Mode

  delay(100);

  lcdcmd(0x0E);  //Display on, cursor blinking

  delay(100);

  lcdcmd(0x01); // clear display screen

  delay(100);

  lcdcmd(0x06); //Increment cursor and shift right

  delay(100);

  lcdcmd(0x80); // force cursor to blink at first row,first position

  delay(100);

  for(i=0;i&lt;7;i++)  // to display 'WIKINOTE' on first row

  {

    lcddata(array[i]);

    delay(1000);

  }

  lcdcmd(0xC0);// force cursor to blink at SECOND row,first position

  delay(100);

  for(i=9;i&lt;19;i++) // to display 'Foundation' on second row

  {

   lcddata(array[i]);

    delay(1000);

  }

  return 0;

}

void delay(unsigned int itime)

{

  int i,j;

  for(i=0;i<itime;i++) 

  for(j="0;j<200;j++);

 }

    void lcdcmd(unsigned int cmd)

    {

    ioclr1=0X00FF0000;// clear previous data which is available on p1.16 to p1.23 pins left="" shift="" value="" by="" 16="" bit="" position=""

    cmd= cmd<<16; //left shift value by 16 bit position

    ioset1=cmd; // send="" shifted="" 

    IOCLR1=0X02000000;//rs=0 ; //for="" command="" register=""

    ioset0=0X20000000; //en="1" ie.high low pulse 

    delay(100);  //call some delay  

    ioclr0=0X20000000; 

    }

      void lcddata(unsigned int data)

    {

    ioclr1=0X00FF0000;// clear previous data which is available on p1.16 to p1.23 pins left="" shift="" value="" by="" 16="" bit="" position=""

    data= data<<16; //left shift value by 16 bit position

    ioset1=cmd; // send="" shifted="" 

    IOSET1=0X02000000; //rs=1 ; //for="" command="" register=""

    ioset0=0X20000000; //en="1" ie.high low pulse 

    delay(100);  //call some delay  

    ioclr0=0X20000000; 

    }

    


References


  • WikiNote Foundation
  • Prof. Sujit Wagh

Last modified: Thursday, 5 March 2020, 1:12 AM