LCD interface with Microcontroller PIC: Beginner’s guide

How to interface LCD (Liquid Crystal Display) display module to PIC microcontroller? LCD is a passive component, that is it does not make any light but just modifies the light passing through it for alphanumeric displays. LCD is exclusively manufactured to be used with microcontrollers, which means that it cannot be triggered by usual IC circuits. This embedded program shows how to connect PIC to LCD display module with microcontroller programming.

Here 16x2 LCD interfaces with the PIC microcontroller. This type of LCD screen can display 2 lines with 16 characters each. Every character consists of 5x8 or 5x11 dot matrix. It can display all the letters of alphabet, Greek alphabet, mathematical symbols, punctuation marks etc. It is also likely to display symbols prepared by the user. Other positive features consist of automatic message shift (left and right), cursor appearance, LED back light etc. Interfacing LCD to microcontroller is quite simple program for beginners and easy to understand.


PIN Description of LDC display module

LCD pin description
EN – Enable:
This control line is used to inform the LCD that you are sending in data. To send data to the LCD, put data on the data bus, then make EN high (1) and wait a little bit and end by bringing EN to low (0) again.

RS - Register Select:
When RS is low (0), the information in the DB0 to DB7 pins are to be considered as an instruction (command- such as Clear screen, Display set, etc.). When RS is high (1), the information in the DB0 to DB7 pins are to be considered valid text data to print on the LCD screen. For example, to display the letter “i” on the screen you should set RS= high.

RW - Read/Write:
When RW is low (0), the information on the data bus is written to the LCD module.

DB0 to DB7:
Data bus lines of LCD display.

Used for enabling back light on the screen. If you don’t want the back light you can leave it unconnected.

Basic connection circuit diagram of LCD interfacing with PIC

(Click on the file to enlarge)
  • We can interface LCD to PIC in 4 bit mode
  • So D0, D1, D2, D3 of LCD display are grounded since connection is 4 bit mode and the D4, D5, D6, D7 are connected to Port C higher bits RC4, RC5, RC6, RC7 respectively.
  • RS pin of LCD module connected to RC2 (PORTC.F2), this will decide whether the LCD inputs are data input or instruction input. In the case of Mikro C compiler we doesn't bother about this pin, only we need to initialize it as sbit LCD_RS at RC2_bit; rest all the operation done by LCD Library function inside Mikro C.
  • RW (Read/Write) pin grounded because we are writing to LCD display. (For writing RW=0; For reading RW=1;)
  • Enable (EN) pin connected to RC3 (PORTC.F3), a HIGH to LOW transition of this pin needed in order to transfer data or command from PIC to LCD module. As I said above, Mikro C LCD library function will do the job for us. Just initialize the bit as sbit LCD_EN at RC3_bit;
You may also like:

Mikro C LCD Library

The Mikro C PRO for PIC offers a library for communication with LCDSs over the 4-bit interface. For executing LCD commands we should add this LCD Library file to the program code.

Go to Library Manager → then add Lcd_Constants and Lcd

External dependencies of LCD Library in Mikro C

Below shows the table including all the initialization commands in LCD library of Mikro C.

Important Library Routines for LCD Module

Initializes LCD module to work with PIC Microcontroller.

Lcd_Out(row, column, “Text”); 
Writes text on LCD beginning from definite position. Both string variables and literals can be passed as a text. row: starting position row number column: starting position column number text: text to be written

Sends command to LCD.

Different types of commands used in LCD library function, the available commands are shown below.

Algorithm for LCD to PIC program

  1. Configure LCD module pin connections.
  2. Set PORTC as Output port.
  3. Setup LCD display. 
  4. Send data to LCD display.

LCD interfacing Embedded C Program for PIC MCU

The enable pin of LCD i.e. the 6th pin need a 1 to 0 transition with a small delay in order to process the input lines. That’s why we are providing a small delay in between all functions.

How to burn this program to PIC MCU?
We had already published articles related to building of .hex files and burning of the microcontroller.

Simulation of LCD display interfacing

The simulation of this LCD interfacing from i-St@r laboratory is shown here. Watch this video demonstration for better understanding.

Related PIC circuits



Post a Comment


Copyright © 2011 CircuitsGallery| ToS | Privacy Policy |

Contact Us | Write For Us | Advertise on Circuits Gallery | About Us