LCD INTERFACING WITH MICROCONTROLLER,In this tutorial, you will learn to interface an LCD with a microcontroller. It is a very simple and easy to understand project for the beginners and is commonly used in several electronic products. LCD (Liquid Crystal Display)provides user interface and can be very useful for debugging purpose. After completion of this tutorial, you will be able to display data on an LCD using mikro C compiler. You should know how to use microcontroller and how to program pic microcontroller.

TASK of LCD interfacing

To interface LCD with PIC16F877A and display the text ‘LCD INTERFACE’ on it. LCDs comes in different sizes and shapes. For this project, we have selected a 16×2 character, alphanumericLCD. It contains 2 rows of 16 character.

Its pin configuration is given as follows:

Pin NumberNameUse
3VeeTo adjust the contrast
4RS1=Data input
0=Instruction input
5R/W1=Read from LCD
0=Write to LCD
6Enable (EN)From 1 to 0 = Data is written to the LCD
7DB0Data Bus Lines

The LCD can work in two modes, 4-bit and 8-bit. In this tutorial, we have used the 4-bit mode which uses only 4 data lines, thus saving pins of the microcontroller. So It is recommended to use LCD in four bits mode to save pins of microcontroller for other purpose.


circuit diagram of LCD interfacing with PIC16F877A microcontroller

circuit diagram of LCD interfacing with PIC16F877A microcontroller

LCD Connections

  • Connect pin1 of LCD to ground and pin2 to Vdd.
  • Pin3 of LCD is used to adjust the contrast of the display. Leave it unconnected.
  • RS (pin4) of LCD is connected to RB2 of PORTB. It distinguishes between data input and command input.
  • RW (pin5) is grounded, since we have to write the data on LCD.
  • E (pin6) is connected to RB3 of PORTB. It is a control line to inform the LCD that data has been sent.
  • D0-D3 of the LCD are grounded, since we are using a 4-bit mode. D4-D7 are connected to the PORTB pins (RB4-RB7) of the controller.



Write the following code in mikroC Compiler

  2. // LCD Module connections
  3. sbit LCD_RS at RB2_bit;
  4. sbit LCD_EN at RB3_bit;
  5. sbit LCD_D7 at RB7_bit;
  6. sbit LCD_D6 at RB6_bit;
  7. sbit LCD_D5 at RB5_bit;
  8. sbit LCD_D4 at RB4_bit;
  9. // End LCD module connections
  10. // LCD Pin direction
  11. sbitLCD_RS_Direction at TRISB2_bit;
  12. sbitLCD_EN_Direction at TRISB3_bit;
  13. sbit LCD_D7_Direction at TRISB7_bit;
  14. sbit LCD_D6_Direction at TRISB6_bit;
  15. sbit LCD_D5_Direction at TRISB5_bit;
  16. sbit LCD_D4_Direction at TRISB4_bit;
  17. // End of LCD Pin direction
  18. void main() {
  19. Lcd_Init();// Initialize LCD
  20. Lcd_Cmd(_LCD_CLEAR);// Clear Display
  21. Lcd_Cmd(_LCD_CURSOR_OFF); // Cursor Off
  22. Lcd_Out(1,1,”LCD INTERFACE”);// Write “LCD INTERFACE” in the first row
  23. }

When using PIC microcontroller, the mikroC compiler has a built-in LCD library that supports the commands to carry out LCD initialization. The library consists of a number of functions to control LCDs with 4-bit data interface.

The main program first clears the LCD screen and then displays “LCD INTERFACE” in the first row of LCD. The LCD pin directions are all set as outputs. The RS pin of LCD is set to 1, which indicates that the information received from DB4-DB7 is a valid text to be printed on LCD screen. The EN pin is also set to 1 which indicates that data is send to the LCD.


Programmed LCDs are vastly used for industrial as well as commercial applications. LCDs are used in UPSs or inverters, where voltage and current readings are displayed on the screen. Instructions to be followed are displayed on an LCD screen in airports, banks, hospitals etc.

If you still have any issue after reading this article, feel free to comment on this post with your issues. To dowlaod code and circuit diagram click on following link :

Code and circuit diagram of LCD interfacing with pic16f877a microcontroller


  1. komen July 14, 2015
    • BILAL Malik July 15, 2015
    • melkamzer March 6, 2017
  2. muthu.m February 4, 2016
  3. niraj singh rauthan March 12, 2016
  4. Nasim June 2, 2016
  5. FARA November 7, 2016
  6. Abdulhamid December 1, 2016
  7. Mani February 14, 2017
  8. parakkath .p February 17, 2017
  9. fares March 3, 2017

Add Comment

Subscribe to our blog to get updates in your email

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 973 other subscribers