Projects   /   LCD & Display Projects   /   PIC18F4550

How to interface 16×2 LCD in 4-bit mode with PIC18F4550

The 16x2 character LCD can work in two modes, namely, 8-bit and 4-bit. These modes basically correspond to the number of data pins used in interfacing LCD.

Published

At a glance

CategoryLCD & Display Projects
PIC modelPIC18F4550
Reading time~3 min

Summary of How to interface 16×2 LCD in 4-bit mode with PIC18F4550

This article explains interfacing a 16x2 LCD with the PIC18F4550 microcontroller in 4-bit mode to save controller pins. It details that only data pins D4-D7 are used, while control pins remain connected as in 8-bit mode. The text describes sending data in two nibbles (high then low) and provides specific Function Set instructions (0x20 and 0x28) for configuration. It also notes that power-up defaults to 8-bit mode, requiring special handling during initialization.

Parts used in the 16x2 LCD Interfacing Project:

  • 16x2 character LCD
  • PIC18F4550 microcontroller
  • Data pins (D4-D7)
  • Control pins (RS, RW, EN)
  • PortB of PIC18F4550

The 16x2 character LCD can work in two modes, namely, 8-bit and 4-bit. These modes basically correspond to the number of data pins used in interfacing LCD. 8-bit mode uses all the data lines and has been explained in LCD interfacing with PIC18F4550. In 4-bit mode, only four data pins of LCD are connected to the controller. This mode, thus, saves four pins of the controller unlike 8-bit mode. The configuration and display method of LCD in 4-bit mode has been explained here.

interface 16x2 LCD

The 8-bit mode of LCD interfacing with PIC has been explained earlier. In the 4-bit mode the (8-bit) data/command is sent in nibble (four bits) format to LCD. The higher nibble is sent first followed by the lower nibble. In 4-bit mode only four data pins (D4-D7) of LCD are connected to the controller. The control pins (RS, RW and EN) are connected the same way as in 8-bit mode. The connections of LCD with PIC18F4550 are shown in the adjoining circuit diagram. Please note that here only PortB is used to connect data lines as well as control lines unlike in 8-bit mode. Refer LCD interfacing with PIC in 8-bit mode.

LCD is configured for 4-bit mode by sending appropriate instruction known as Function Set. The Function Set is hexadecimal instruction for LCD MPU unit which selects the working modes of LCD. The Function Set is given below along with its description.
Instruction
RS
RW
D7
D6
D5
D4
D3
D2
D1
D0
Function Set
0
0
0
0
1
DL
N
F
-
-
Description: 
DL       -           Data Length
N         -           No. of Lines
F          -           Font
 Value
 DL
 N
F
1
8 bit
2 lines
5x10 dots
0
4 bit
1 line
5x7 dots
According to the table, the value of Function Set for 4–bit mode will be [ 0010 0000 ] 0x20. The value of Function Set for the LCD configuration : 2 line (N=1), 5x7 dots (F=0) and 4-bit (DL=0) mode will be [ 0010 1000 ] 0x28.
It is important to note that when the power supply is given to LCD, it remains in 8-bit mode. In this state if 0x20 is sent, lower nibble will not be received by LCD because only four data lines (D4-D7) are connected, so 0x02 is sent instead of 0x20.
  • How many data pins are used in 4-bit mode?
    Only four data pins (D4-D7) are connected to the controller.
  • What is the order of sending data in 4-bit mode?
    The higher nibble is sent first followed by the lower nibble.
  • Which instruction selects the working modes of the LCD?
    The Function Set instruction is used to select the working modes.
  • What is the Function Set value for 4-bit mode?
    The value is 0x20 or [0010 0000].
  • What is the Function Set value for 2-line 4-bit mode?
    The value is 0x28 or [0010 1000].
  • In which mode does the LCD remain when power is supplied?
    The LCD remains in 8-bit mode when power is supplied.
  • Why is 4-bit mode preferred over 8-bit mode?
    It saves four pins of the controller compared to 8-bit mode.
  • What happens if 0x20 is sent immediately after power up?
    Only 0x02 is received because the lower nibble is not received on the four connected lines.
Beginner Tutorials · PIC18F4550

PICDEM FS USB CDC Evaluation Board using PIC18F4550 with Proteus Simulation

Introduction The PICDEM FS USB CDC Evaluation Board is a practical microcontroller project built around the PIC18F4550, designed to demonstrate USB communication...

Peripheral Tutorials · PIC18F4550

PICDEM FS USB Mass Storage Device using PIC18F4550 with Proteus Simulation

Introduction This microcontroller project demonstrates how to simulate a USB Mass Storage Device (MSD) using the PIC18F4550 in a Proteus simulation environment....

Development Boards & Kits · PIC18F2550

Pinguino Project: A PIC Microcontroller Based Arduino

This is a complete tutorial to make a PIC Microcontroller based Arduino. This is a complete tutorial to make PIC microcontroller based...

LCD & Display Projects

Leveraging Blockout Banners for Effective Electronics and Tech Product Displays

Blockout banners have become a popular and effective tool for displaying electronics and tech products in various settings, from trade shows and...

LCD & Display Projects · PIC18F4520

Interfacing PIC18F4520 microcontroller with an HD44780 LCD

Introduction Being able to display data from a microcontroller visually has many advantages. It allows for menus, status indicators, and instructions to...

LCD & Display Projects

Video Project Development in the Midst of an Impromptu Online Semester

Receiving robot parts in the mail was an unexpected conclusion to the Winter 2020 semester for students. However, when faced with a...

Ibrar Ayyub

Ibrar Ayyub

I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough...