avatar

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.

How+to+Interface+LCD+to+PIC16F877A+Microcontroller LCD interface with Microcontroller PIC: Beginner’s guide

PIN Description of LDC display module

LCD+Module+pin+description LCD interface with Microcontroller PIC: Beginner’s guide

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.

Basic connection circuit diagram of LCD interfacing with PIC

LCD+interfacing+with+PIC16F877A LCD interface with Microcontroller PIC: Beginner’s guide
(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

Mikro+C+LCD+Library+functions LCD interface with Microcontroller PIC: Beginner’s guide

External dependencies of LCD Library in Mikro C

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

LCD+Library+Commands LCD interface with Microcontroller PIC: Beginner’s guide

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.

LCD+Commands LCD interface with Microcontroller PIC: Beginner’s guide

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
// LCD module connections
sbit LCD_RS at RC2_bit;
sbit LCD_EN at RC3_bit;

sbit LCD_D7 at RC7_bit;
sbit LCD_D6 at RC6_bit;
sbit LCD_D5 at RC5_bit;
sbit LCD_D4 at RC4_bit;
// End LCD module connections

// LCD Pin direction
sbit LCD_RS_Direction at TRISC2_bit;
sbit LCD_EN_Direction at TRISC3_bit;

sbit LCD_D7_Direction at TRISC7_bit;
sbit LCD_D6_Direction at TRISC6_bit;
sbit LCD_D5_Direction at TRISC5_bit;
sbit LCD_D4_Direction at TRISC4_bit;
// End of LCD Pin direction

void main()

{
Lcd_Init(); // Initialize LCD
Lcd_Cmd(_LCD_CLEAR); // Clear display
Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor off
Lcd_Out(1,1,"Circuits Gallery");//Write text “Circuits Gallery” in first row
}


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

4 thoughts on “LCD interface with Microcontroller PIC: Beginner’s guide

    • 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>