Interfacing PIC16F877A with LCD using CCS C compiler

PIC16F877A LCD example
PIC16F877A LCD example hardware circuit 

This topic shows a simple example for interfacing LCD display (with HD44780 or compliant controller) with PIC16F877A microcontroller using CCS PIC C compiler. 
In 4-bit mode there are 7 data lines between the PIC microcontroller and the LCD which are: RS, R/W, E, D4, D5, D6 and D7.

Hardware Required:

  • PIC16F877A microcontroller   —> datasheet
  • 1602 LCD display
  • 8 MHz crystal oscillator
  • 2 x 22 pF ceramic capacitor
  • 10k Ohm resistor
  • 10k Ohm variable resistor (or potentiometer)
  • PIC microcontroller programmer (PICkit 3, PICkit 4 …)

Interface PIC16F877A with LCD circuit:
PIC16F877A LCD example circuit schematic diagram is shown below.
PIC16F877A LCD example circuit
As the PIC16F877A microcontroller has no internal oscillator circuit, a crystal oscillator with 8MHz is used as a clock source for the microcontroller. The MCLR pin of the microcontroller is connected to +5V through 10k Ohm resistor.
The microcontroller is supplied with 5 Volts where the positive terminal of the power source is connected to VDD pins (#11 & #32) and the negative terminal is connected to VSS pins (#12 & #32), power pins are not shown in the circuit diagram.

The LCD used in this example has 2 lines and 16 columns, its connection is as described below:
VDD & VSS pins are power supply pins of the LCD module where VDD is connected to positive terminal of the power supply and VSS is connected to negative terminal.
VEE Pin (also known as V0) of the LCD module is connected to a 10k Ohm variable resistor output. The usage of the variable resistor allows us to easily control the contrast of the LCD display.
RS (Register Select) Pin is connected to pin RC0 of PIC16F877A microcontroller.
RW (Read/Write) Pin is connected to pin RC1.
E (Enable) Pin of the LCD is connected to pin RC2 of the PIC16F877A MCU.
Data pins, D4, D5, D6, & D7 are respectively connected to MCU pins RC3, RC4, RC5, & RC6.
A and K pins of the LCD are backlight LED anode and cathode terminal, they are respectively connected to GND and +5V (not shown in circuit diagram).
Pins D0, D1, D2, & D3 are not connected pins because 4-bit mode is used, alternatively, they can be connected to ground.

Interface PIC16F877A with LCD display C code:
The C code below was tested with CCS C compiler version 5.051.

Interface PIC16F877A with LCD video:

Leave a Comment

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Scroll to Top