LCD(Liquid Crystal Display) screen is such a display module and a 16×2 LCD module is very commonly used. These modules are replacing seven segments and other multi segment LEDs for these purposes. The reasons being: LCDs are economical, easily programmable, have no limitation of displaying special & even custom characters (unlike in seven segments), animations and so on. LCD can be easily interfaced with a microcontroller to display a message or status of a device. This topic explains the basics of a 16×2 LCD and how it can be interfaced with AT89C51 to display a character.
LCD Pins Description:
A 16×2 LCD means it can display 16 characters per line and there are 2 such lines. In this LCD each character is displayed in 5×7 pixel matrix.
Now we are familiar with the pins of the LCD as well as the commands to the instruction registers of the LCD. Now let us discuss some basic codes which will be required whenever we want to interface LCD with the microcontroller.
An LCD interfaced to microcontroller looks like:
LCD Interfacing Code Segments:
LCD Initialization Code:
First code we are going to discuss is the LCD initialization code. In this code segment different hex codes (table given above) are passed to the LCD instruction register to properly initialize the LCD.
MOV A, #38H
MOV A, #0CH
MOV A, #06H
SendingCommand to LCD:
When we want to send some command to LCD we use following code segment.
MOV P1, A
When we want to send some command to LCD we set RS pin equal to zero. After clearing the RS pin we move the command to the port of the microcontroller. Next we toggle the EN pin to move the command from the port the LCD.
Sending Character to LCD:
Following code serves the purpose of sending character to LCD.
MOV P1, A
When we want to send some character to LCD we set RS pin equal to one. After setting the RS pin we move the data to the port of the microcontroller. Next we toggle the EN pin to move the data from the port the LCD.
Writing String to LCD:
The following code serves the purpose of writing a string to LCD.
MOV R1, #0
REPEAT: MOV A, R1
In the above code segment we first move value of Zero to R1 and then we move the value from R1 to Accumulator. Next using MOVC command we calculate the address. JZ commands moves the control to the label exit when the value in the accumulator is zero. Next we call Write character function to write it to LCD. Then we increment R1 and this loop continues so on.
Clearing the LCD:
The following code serves the purpose of clearing the LCD.
MOV A, #01H
Moving To A Particular Address Of LCD:
The following code provides us the service to move to a particular address of the LCD.
ADD A, #80H
Here you go.