LAB5 - Interfacing With LCD
LAB5 - Interfacing With LCD
1. Objectives:
- Describe the functions of the pins of a typical LCD
- Learn how to interface 16x2 Alphanumeric LCD with PIC in an 4-bit Mode.
- Program an LCD in C.
2. Components
LCD
PIC18F4550
Preset
3. Introduction to LCD
LCDs (Liquid Crystal Displays) are used for displaying status or parameters in embedded
systems.
LCD 16x2 is a 16 pin device which has 8 data pins (D0-D7) and 3 control pins (RS, RW,
EN). The remaining 5 pins are for supply and backlight for the LCD.
The control pins help us configure the LCD in command mode or data mode. They also
help configure read mode or write mode and also when to read or write.
LCD 16x2 can be used in 4-bit mode or 8-bit mode depending on the requirement of the
application. In order to use it we need to send certain commands to the LCD in command
mode and once the LCD is configured according to our need, we can send the required
data in data mode.
4-bit Mode
Interfacing Diagram
Programming Steps:
Before displaying anything on LCD, it needs to be configured with proper
instructions. The following programming steps explain the procedure of configuring the
LCD and display a character on it.
Step 1: Initialize the LCD.
1. Send the command byte to the port connected to LCD data pins
2. RS=0, to select command register of LCD
3. RW=0, to set the LCD in writing mode
4. EN=1, a high to low pulse to latch command instruction
5. Delay of 1ms
6. EN=0
The above set of commands is written in lcdcmd(unsigned char) function.
Step 3: Send data to LCD.
1. Send data at the port which connected to LCD data pins
2. RS=1, register select to select data register of LCD
3. RW=0, this set the LCD in writing mode
4. EN=1, a high to low pulse to latch data
5. EN=0
The lcddata(unsigned char) function has the above set of instructions.
Step 4: Display character on LCD.
The functions lcdcmd() and lcddata() are user-defined functions. They are used to
send a character (E in this case) to be displayed on LCD.
lcdcmd(0x38); // send command 0x38 to LCD
lcddata(‘E’); // send character E to LCD
4. Experiment
4.1. Activity 1
- Connect the circuit using Proteus with PIC18F4550
- Write a program using MPLABX to display your name on line 1 of the LCD (first
name followed by last name with a space in between).
Note: If you are not monitoring the busy flag of the LCD, put a few milliseconds
delay in your program.
- Simulate the circuit using Proteus ISIS program.
4.2. Activity 2
Repeat Activity 1 while also putting the year you graduated from high school on the
second line. When you run your program, the LCD should show (for example):
Thu Ha
Graduated in 2021
4.3. Activity 3
Write an LCD program to display your last name on the first line and the birth year
on the second line. Both should be in the middle of the line.
5. Homework
Write an LCD program to display “Hello” on 1 st row, 5th location and display your
name on 2nd row, 1st location.