Table of Contents
Introduction to LCD
How to interface LCD with PIC18f4550 microcontroller? LCD also known as liquid displays are widely used these days for displaying characters, numbers, and graphics. They are more advanced displaying devices as compared to simple LEDs or Seven Segment displays. They are also used because of the following reasons:
- The declining prices of LCDs.
- Ease of Programming.
- They have the latching ability.
- Incorporation of refreshing controlling sets CPU free to refresh it.
There are different manufacturers of LCDs and they do come in many styles. Some of the LCDs are are 16×2 size, some are 20×2 etc.
Manufacturers of LCDs
Optrex is one of the largest manufacturers of LCD. You can easily find datasheet of LCDs from their website. Other famous manufacturers are:
For alphanumeric displays, 16×2 is recommended and it is easy to configure.
Pin description of LCD
There are 8 data lines (8 pins) for displaying the characters/numbers on LCDs. On these data lines microcontroller will be sending data for display. There are control pins: RS (Register Select), R/W (Read/write: W is an active low pin. It means write operation can be performed by sending 0 logic to it). E (enable Pin).
What is the RS pin of LCD?
Register Select (RS) is used for selecting the internal register of LCD. There are two internal registers corresponding to this pin.
If RS=0 then command register is selected. The command register is used for issuing commands to LCD. These commands are used for configuring the LCD. The configuration involves the selection of the internal matrix, clearing data of LCD, cursor blinking and positioning the cursor etc. Here is the list of the commands that can be used for configuring the LCD.
|Hex Code||Command instructions|
|1||Clear display scree|
|5||Shift display right|
|7||Shift display left|
|8||Display off, power off|
|A||Display off, cursor ON|
|C||Display ON, cursor OFF|
|E||Display ON, cursor blinking|
|F||Display OFF, cursor blinking|
|10||Shift cursor position to left|
|14||Shift cursor position to right|
|18||Shift the entire display to the left|
|1C||Shift the entire display to the right|
|80||Force cursor to the beginning of the 1st line|
|C0||Force cursor to the beginning of the 2nd line|
|38||2 lines and 5X7 matrix|
If RS=1 then data register is selected. In order to send the data for display we will set RS=1.
R/W= If R=0 it means writing operation is being performed on the LCD for displaying the data. It is an active low pin as explained above. If we want to program the LCD for displaying the data by monitoring the busy pin (D7) of LCD then we will be reading its state by setting R/W=1.
This pin is used for latching the data on data lines of LCD. In order to display a character on LCD it needs to be latched for a small duration. This is done by sending a high to low pulse on enable pin. The duration of this pulse should be around 150 msec.
Vcc/Vdd pin of LCD
For powering up the LCD, we need to provide +5V on Vcc or Vdd pin.
It is grounded.
This pin is used for controlling the contrast of LCD display. We will connect a variable resistor on this pin for controlling the contrast.
|Pin Number||Pin Name||Description|
|1,2,3||Vss,Vcc,Vee||Ground, Power Supply +5V, Contrast control|
|4||RS||RS=0 (command Register)
RS=1 (Data Register)
|5||R/W||R/W=0 (Write Operation)
R/W=1 (Busy status test)
|6||E||Enable pin for latching the data on datalines|
LCD connection with PIC microcontroller
Flow chart for connecting/interfacing the LCD with PIC18f4550 Microcontroller
Code for interfacing LCD with pic microcontroller in assembly language
In this code PORTD is connected with data lines of LCD and first three pins of PORTB are used for control signals RS, R/W and Enable
The following code is run on MPLAB software.
R1 EQU 0X04
R2 EQU 0X05
R3 EQU 0X06
R4 EQU 0X07
R5 EQU 0X08
R6 EQU 0X09
YOU BTG PORTB,0
COMMAND MOVWF PORTD
READY SETF TRISD
BAC BSF PORTB,2
DELAY MOVLW D’20’
L22 MOVLW D’52’
L11 MOVLW D’50’
SDELAY MOVLW D’10’
L2 MOVLW D’10’
L1 MOVLW D’100′
Lab Manual for LCD and Keypad Interfacing
Also read here