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.
|Clear display scree
|Shift display right
|Shift display left
|Display off, power off
|Display off, cursor ON
|Display ON, cursor OFF
|Display ON, cursor blinking
|Display OFF, cursor blinking
|Shift cursor position to left
|Shift cursor position to right
|Shift the entire display to the left
|Shift the entire display to the right
|Force cursor to the beginning of the 1st line
|Force cursor to the beginning of the 2nd line
|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.
|Ground, Power Supply +5V, Contrast control
|RS=0 (command Register)
RS=1 (Data Register)
|R/W=0 (Write Operation)
R/W=1 (Busy status test)
|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