4 bit LCD Interfacing with PIC Microcontroller

/, Firmware Guide-PIC/4 bit LCD Interfacing with PIC Microcontroller

4 bit LCD Interfacing with PIC Microcontroller

In the previous chapter, we discussed how a character LCD is interfaced with a PIC microcontroller in 8-bit mode. A character LCD can be configured in 8 bit or 4-bit mode in which 8 data pins and 4 data pins are used respectively this feature allows efficient use of the digital I/0 pins of the microcontroller. This article explains 4 bit LCD interfacing with PIC Microcontroller.

Character LCD

A 16×2 character liquid crystal display (LCD) module is the most basic electronic display module which is widely used. The module will consist of 2 rows each with 16 columns which can display 16 characters. Several other LCD modules are also available like 20×4 dimension LCD which can display 20 characters per line and 4 such lines would be available. The choice for the module depends on the requirement.

The main advantage of using a character LCD instead of a seven segment display and other multi-segment LEDs is that there is no limitation in displaying special & custom character animations and so on. All character LCDs will have 16 pins among which 8 are data pins through which data or commands are passed into the LCD registers.

Charactor-lcd

Features

The features of a character LCD module make it more suitable as an electronic display than 7 segment displays and other multi-segment display modules. Most importantly the module can be interfaced much easily unlike other modules with no complexity in both hardware and software.The 4-bit mode interfacing of the LCD module enables an efficient method of saving the number of general purposes I/O pins which is a major criterion for an embedded system designer. There is no limitation in characters which can be displayed using the module. The contrast of the module can be adjusted using the VEE pin of the module and LED backlight can be enabled with LED+ and LED- which makes the display more bright.

Register

A Character LCD consists of two registers

  1. Command register
  2. Data register

The RS(Register Select) pin of the LCD module is used to select the specific register. When RS is low, command register is selected and when RS is high, data register is selected. State of R/W pin determines the operation to be performed whether to read or write data.

All instructions to be executed by the LCD are latched into the command register of the LCD. LCD commands include a clear display, the cursor on/off, display shift and so on.

Character to be displayed on the LCD is stored in the data register. The data is stored temporarily in the data register.

Commands

Commands are instructions given to the LCD module to perform a predefined task. The task to be performed is defined by the manufacturer. Some of the LCD commands are listed below.

  1. Clear display – 0x01
  2. The display on, cursor off – 0x0C
  3. Increment cursor – 0x04

The rest of the commands can be obtained from the device datasheet.

Sending commands

Hardware setup for interfacing the character LCD in 4-bit mode is by connecting the 4 data lines to the GP I/O pins of the controller. Sending a command or data into an LCD configured in 4-bit mode from 8-bit mode such that data need to be sent a nibble after the another. MSB of the data is sent first followed by LSB.

The LCD can be configured in 4-bit mode by sending appropriate instruction which is called ‘Function set’ to it. The function set is the hexadecimal instruction for the LCD MPU to select the working model of LCD. According to the table in the datasheet of the LCD module, the value of function set to initialize the LCD module in 4-bit mode can be calculated as 0x20.

RS, RW and Enable pins should be macro defined in the firmware for example.

Since we know that only for data lines will be connected in hardware with the microcontroller port. The data needs to be sent in 4 bits. MSB nibble can be sent in first followed by LSB nibble. For example:

It is not mandatory to follow the above-given logic. The control port is selected different from data port to reduce the complexity of the firmware.

Sending data

Sending data to a 4 bit LCD follows the same method as done with the command except that the data register needs to be selected instead of the command register by driving the RS line high.

lcd-wave-form-read

4 bit LCD interfacing with PIC Microcontroller – Circuit diagram

4 bit LCD interfacing with PIC Microcontroller

Character LCD 4-bit interfacing circuit

 

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
Spread the love, share this

2 Comments

  1. Naren July 14, 2018 at 11:14 am

    I can”t understand why you used Data_PORT=0x20; during Initial setup of LCD.What was the reason behind using it?

Leave A Comment

DON’T MISS OUT UPDATES!
Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
close-link
Request Demo
25% OFF - OpenLabPro Course
Use Coupon: CRS25UL

 
PIC Microcontroller Primer
Want to learn indepth programming, peripheral interfacing and driver development?
close-link
Launched: IoT online Course - 25% Off when you complete your order today.
Checkout Now
close-image

I'm interested in OpenLab Platform

Get a detailed demo of OpenLab platforms at your convenient time!
Contact me for a demo
close-link

Subscribe To our Email Newsletter

Be the first to get latest updates and exclusive content straight to your email inbox.
Send me Tutorials and Guides
close-link