Search
Close this search box.

Home

Interfacing 16×2 LCD with 8051

In this project, we will have brief discussion on how to interface 16×2 LCD module to AT89C51, which is an 8051 family microcontroller. We use LCD display for the displaying messages in a more interactive way to operate the system or displaying error messages etc. Interfacing 16×2 LCD with 8051 microcontroller is very easy if you understanding the working of LCD.

Hence, in this project, I will not only give the information of LCD and also provide the code in C language which is working fine without any errors.

Also get an idea about Interfacing LEDs with 8051 Mirocontroller

A Brief Note on 16×2 LCD

16×2 Liquid Crystal Display which will display the 32 characters at a time in two rows (16 characters in one row). Each character in the display is of size 5×7 pixel matrix. This matrix differs for different 16×2 LCD modules, if you take JHD162A, this matrix goes to 5×8. There are 16 pins in the LCD module, the pin configuration us given below

PIN NO
NAME
FUNCTION
1
VSS
Ground pin
2
VCC
Power supply pin of 5V
3
VEE
Used for adjusting the contrast commonly attached to the potentiometer.
4
RS
RS is the register select pin used to write display data to the LCD (characters), this pin has to be high when writing the data to the LCD. During the initializing sequence and other commands this pin should low.
5
R/W
Reading and writing data to the LCD for reading the data R/W pin should be high (R/W=1) to write the data to LCD R/W pin should be low (R/W=0)
6
E
Enable pin is for starting or enabling the module. A high to low pulse of about 450ns pulse is given to this pin.
7
DB0
8
DB1
9
DB2
10
DB3
11
DB4
DB0-DB7 Data pins for giving data(normal data like numbers characters or command data) which is meant to be displayed
12
DB5
13
DB6
14
DB7
15
LED+
Back light of the LCD which should be connected to Vcc
16
LED-
Back light of LCD which should be connected to ground.

So by reading the above table you can get a brief idea how to display a character. For displaying a character you should enable the enable pin (pin 6) by giving a pulse of 450ns, after enabling the pin6 you should select the register select pin (pin4) in write mode. To select the register select pin in write mode you have to make this pin high (RS=1), after selecting the register select you have to configure the R/W to write mode that is R/W should be low (R/W=0).

Follow these simple steps for displaying a character or data

  • E=1; enable pin should be high
  • RS=1; Register select should be high
  • R/W=0; Read/Write pin should be low.

To send a command to the LCD just follows these steps:

  • E=1; enable pin should be high
  • RS=0; Register select should be low
  • R/W=0; Read/Write pin should be low.

Commands: There are some preset commands which will do a specific task in the LCD. These commands are very important for displaying data in LCD. The list of commands given below:

Command
Function
0F
For switching on LCD, blinking the cursor.
1
Clearing the screen
2
Return home.
4
Decrement cursor
6
Increment cursor
E
Display on and also cursor on
80
Force cursor to beginning of the first line
C0
Force cursor to beginning of second line
38
Use two lines and 5x7 matrix
83
Cursor line 1 position 3
3C
Activate second line
0C3
Jump to second line position 3
0C1
Jump to second line position1

To get the detailed information, Click Here and Download the Datasheet

Interfacing 16×2 LCD with 8051 Circuit Diagram

Interfacing 16×2 LCD with 8051 Circuit Diagram

Components Required 

  • AT89C51 (8051 Microcontroller)
  • 16X2 LCD Display
  • 11.0592MHz Crystal
  • 2 X 33pF Capacitors 
  • 2 X 10 KΩ Resistors
  • 1 KΩ X 8 Resistor Pack 
  • 10 KΩ Potentiometer 
  • 330Ω Resistor 
  • Push Button 
  • 10μF/16V Capacitor 
  • 8051 Programmer 
  • 5V Power Supply 
  • Connecting Wires

Circuit Explanation

The crystal oscillator, along with two 33pF Capacitors, are connected to XTAL1 and XTAL2, which will provide the system clock to the microcontroller. 

RST Pin is pulled-LOW with the help of a 10KΩ Resistor. With the help of a 10μF Capacitor and a Push Button, you can reset the 8051 Microcontroller. EA is pulled-HIGH with the help of a 10KΩ resistor. 

The data pins of the LCD are connected to PORT0 (first, the PORT0 pins must be pulled-HIGH with the help of a 1KΩ Resistor Pack). RS and E are connected to PORT2 pins P2.0 and P2.1.

A 10KΩ Potentiometer is used to adjust the contrast of the LCD. 

Interfacing 16×2 LCD with 8051 Image 1
Interfacing 16×2 LCD with 8051 Image 2
Interfacing 16×2 LCD with 8051 Image 3

Programming LCD to 8051

Coming to the programming you should follow these steps:

  • STEP1: Initialization of LCD.
  • STEP2: Sending commands to LCD.
  • STEP3: Writing the data to LCD.

[Also Read: How To Make an Adjustable Timer ]

Initializing LCD

To initialize LCD to the 8051 the following instruction and commands are to be embed in to the functions

  • 0x38 is used for 8-bit data initialization.
  • 0xoC for making LCD display on and cursor off.
  • 0X01 for clearing the display of the LCD.
  • 0x80 for positioning the cursor at first line .

Sending Commands to the LCD

  • E=1; enable pin should be high
  • RS=0; Register select should be low for sending commands
  • Placing the data on the data registers
  • R/W=0; Read/Write pin should be low for writing the data.

Writing the Data to the LCD

  • E=1; enable pin should be high
  • RS=1; Register select should be high for writing data
  • Placing the data on the data registers
  • R/W=0; Read/Write pin should be low for writing the data.

Important Post – Interfacing 7 Segment Display with 8051 Microcontroller

Code 

Additional Codes 

The programs given below will use above functions and display the complete string which is given by the programmer to display the data. We have provided two demo codes working properly and easy to understand.

Code 1

Code 2

Related Post: Real Time Clock (RTC) Interfacing PIC18F

20 Responses

  1. hi….this is sandhya….we are dng project using lcd display. so we want program coding in keil for displaying the received data….?

    1. Below is a simple code written in assembly using keil..The code displays HELLO.
      The code is written for 8051 uc. For info on pin connections or other things,email me- srihariash@gmail.com

      ORG 0000H
      HERE: MOV A,#38H
      ACALL CMND
      MOV A,#0FH
      ACALL CMND
      MOV A,#06H
      ACALL CMND
      MOV A,#01H
      ACALL CMND
      MOV A,#080H
      ACALL CMND

      MOV A,#’ ‘
      ACALL DISP
      MOV A,#’H’
      ACALL DISP
      MOV A,#’E’
      ACALL DISP
      MOV A,#’L’
      ACALL DISP
      MOV A,#’ L’
      ACALL DISP
      MOV A,#’O’
      ACALL DISP

      SJMP HERE

      CMND: MOV P2,A
      CLR P3.5
      CLR P3.4
      SETB P3.3
      CLR P3.3
      RET

      DISP: MOV P2,A
      SETB P3.5
      CLR P3.4
      CLR P3.3
      SETB P3.3
      RET

      END

  2. superb site i have seen , coz programing is very good written nd undetstood quite easily….
    thank you………..

  3. i understood how to display simple characters.
    but suppose i want to display a string(eg: “my name is xyz”) then what should i do?
    should i just put the string in lcddata funcion? or do ineed to manually shift the data to left for showing space and other characters in same line?

  4. Sir I am designing digital presaure measurment display…I am confuse that I give a anlog signal to adc and it convert that into digital and I want to display preesure according to signal applied to the adc 0808 how can I do that..??

  5. I want to read real time values from sensors through microcontroller and display it here. Will this code work or if no then can anyone help me with the code in keil vision software

Leave a Reply

Your email address will not be published. Required fields are marked *