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.
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
- 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
- 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.
[cc lang=”C”]// 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
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.