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 16×2 LCD interfaces with the PIC microcontroller. This type of LCD screen can display 2 lines with 16 characters each. Every character consists of 5×8 or 5×11 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

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.

LED+, LED-:
Used for enabling back light on the screen. If you don’t want the back light you can leave it unconnected.

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.

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;

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

Lcd_Init();
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

Lcd_Cmd(_LCD_CLEAR);
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

Configure LCD module pin connections.

Set PORTC as Output port.

Setup LCD display.

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.

Hi Sankari,
As you can see in the simulation this circuit will work perfectly. Try to double check your connection diagram and program.
Please provide me the methods that you had followed for compiling.