LCD Interfacing with 8051 Microcontroller

   A decade back the process and control operations were implemented by using the microprocessor only. But nowadays the situation is changed and it is occupied by a new device called Microcontroller. We can’t find any electronic gadget without the use of a Microcontroller because the development is so drastic. The Microcontroller has changed the embedded system design so simple and advanced.


LCDs use two sheets of polarizing material with a liquid crystal solution placed between them. When electric current passed through the crystal solution, the crystals get aligned so that light cannot pass through them. Each crystal is thus like a shutter, either allowing light to pass through or block it. There are two kinds of LCD such as color and monochrome. For projects, we use monochrome, while for TV, Laptops we use color. Color LCD uses two basic techniques for producing color. This article discusses LCD interfacing with 8051 microcontrollers.

What is a Microcontroller?

A Microcontroller is a small computer in an integrating circuit that contains memory, programmable input, and output peripherals, processor core. Microcontroller primarily designed for embedded applications while Microprocessor designed for personal computers or general-purpose applications. Microcontroller instructions are both bit addressable as well as byte-addressable. It has instruction sets catering to the control of inputs and outputs.

8051 Microcontroller
8051 Microcontroller

LCD Interfacing Module Review

16×2 LCD module is a very common type of LCD module to be used in 8051 based embedded projects. It has 16 rows and 2 columns [5×7] or [5×8] LCD dot matrices. The module we will use is number JHD162A. Available in 16 pin packages with features like contrast adjustment function, backlight, and each dot matrix has 5×8 dot resolution.

The PINs, their name and functions are shown in the table below

16×2 LCD pin number, name and functions

  • VEE pin 3 adjusts the contrast of the LCD by varying voltage at this pin. Performed by connecting one end to ground potential and others to VCC (5V).
  • R/W pin 5 selects between reading and write modes. LOGIC HIGH at pin facilitates READ mode and the LOW level on this pin facilitates WRITE mode.
  • JHD162A has 2 inbuilt registers. Logic High (1) at RS pin 4 selects the data register. Inserts data on the data line, the module will recognize it as a command. Logic Low (0) logic at the RS pin will select the command register.
  • Data register- place the data to be displayed
  • Command register- places the commands. Inserts data in 8-bit data line (DB0 to DB7), the LCD module recognizes it as data to be displayed
  • E pin 6 turns on the module. A high to low transition on this pin will switch on the module.
  • DB0 to DB7 are data pins. The data to be displayed and the command instructions are placed on these pins.
  • LED (+) is the backlight, LED anode and this pin must be connected to Vcc through a series current limiting resistor of appropriate value. LED (-) is the backlight, LED cathode and this pin must be connected to the ground.
  • 16×2 LCD module commands

16×2 LCD module contains a set of preset command instructions. Each command will make the module to do a particular task. The commonly used function and their commands are given in the table below.

PCBWay

16×2 LCD module command and function

LCD Initialization

For initializing the LCD, the following are the steps that are given below and these steps are the same for almost all the applications.

  • Send 38H to the 8-bit data line for initialization
  • Send 0FH for making LCD ON, cursor ON, cursor blinking ON
  • Send 06H for incrementing cursor position
  • Send 01H for clearing the display and return the cursor

Sending Data to the LCD

The following are the steps for sending the data to the LCD module which is given below. The logic state of these pins that make the module to determine whether a given data input is a data or command to be displayed.

  • Make R/W low
  • Make RS=1, if the data byte is a data to be displayed and make
  • RS=0, if the data byte is a command.
  • Place data byte on the data register
  • Then pulse E from high to low
  • Repeat the above steps for sending other data

Circuit Diagram of LCD interfacing of 8051 Microcontroller

The circuit diagram of Interfacing 16×2 LCD module with AT89S51 Microcontroller is as shown above. Resistor R3, Capacitor C3 and push button switch S1 will form the reset circuitry. Crystal X1 and ceramic capacitors C1, C2 are related to the clock circuitry which will produce the system clock frequency. P1.0 to P1.7 pins of the microcontroller is connected to the module DB0 to DB7 pins respectively, this route the data that goes to the LCD module. P3.3, P3.3, and P3.5 connect to the E, R/W, RS pins of the microcontroller, and this route the control signals which are transferred to the LCD module. R1 resistor limits the current through the LED backlight and the backlight intensity. POT R2 is used for adjusting the contrast of the display. The program for interfacing LCD with 8051 microcontrollers is as shown below.

LCD Interfacing Circuit Diagram
LCD Interfacing Circuit Diagram

Program for LCD interfacing to 8051 Microcontroller

MOV A, #38H / / Use 2 lines and 5×7 matrix
ACALL CMND
MOV A, #0FH / / LCD ON, cursor ON, cursor blinking ON
ACALL CMND
MOV A, #06H / / Increment cursor
ACALL CMND
MOV A, #82H / / Cursor line one, position 2
ACALL CMND
MOV A, #3CH / / Activate second line
ACALL CMND
MOV A, #49D
ACALL DISP
MOV A, #54D
ACALL DISP
MOV A, #88D
ACALL DISP
MOV A, #50D
ACALL DISP
MOV A, #32D
ACALL DISP
MOV A, #76D
ACALL DISP
MOV A, #67D
ACALL DISP
MOV A, #68D
ACALL DISP
MOV A, #0C1H / / Jump to second line, position 1
ACALL CMND
MOV A, #67D
ACALL DISP
MOV A, #73D
ACALL DISP
MOV A, #82D
ACALL DISP
MOV A, #67D
ACALL DISP
MOV A, #85D
ACALL DISP
MOV A, #73D
ACALL DISP
MOV A, #84D
ACALL DISP
MOV A, #84D
ACALL DISP
MOV A, #83D
ACALL DISP
MOV A, #84D
ACALL DISP
MOV A, #79D
ACALL DISP
MOV A, #68D
ACALL DISP
MOV A, #65D
ACALL DISP
MOV A, #89D
ACALL DISP
HERE: SJMP HERE
CMND: MOV P1, A
CLR P3.5
CLR P3.4
SETB P3.3
CLR P3.3
ACALL DELY
RET
DISP: MOV P1, A
SETB P3.5
CLR P3.4
SETB P3.3
CLR P3.3
ACALL DELY
RET
DELY: CLR P3.3
CLR P3.5
SETB P3.4
MOV P1, #0FFh
SETB P3.3
MOV A, P1
JB ACC.7, DELY
CLR P3.3
CLR P3.4
RET
END

This is all about LCD interfacing with 8051 microcontrollers. We believe that the information given in this article is helpful for you for a better understanding of this project. Furthermore, any queries regarding this article or any help in implementing the electrical and electronics projects, you can feel free to approach us by connecting in the comment section below. Here is a question for you, what is the code for LCD interfacing with 8051 microcontrollers?

Photo Credits:

LCD interfacing with 8051 Microcontroller circuitstoday