Interfacing Graphical LCD(GLCD-JHD12864E) with Microchip PIC16f877 Microcontroller

In this post/tutorial i am going to teach you how to interface graphical lcd jhd12864E with microchip pic16f877 microcontroller. I am going to display my website name “” and a special pattern that displays thick lines on dotted graphical lcd display. In graphical lcd name “jhd12864” the number 128×64 means lcd has 128 coulombs and 64 rows. On graphical lcd’s data(character, numbers) is displayed on dots. A joint between coulomb and row is termed as dot. Total dots present in jhd12864 lcd are 128 x 64 = 8192 dots. When dots are combined they make a dot cluster. This cluster of dots in square form is know as matrix. On these 8192 dots we can display/make our data(character, number, image). In graphical lcd’s we are free to make character’s of our desired size unless the size is in the matrix of graphical lcd.
Interfacing Graphical LCD(GLCD-JHD12864E) with Microchip PIC16f877 Microcontroller
Before proceeding i would recommend you to please go through a small tutorial. This tutorial will helps you to understand how text is displayed on graphical lcd, how graphical lcd dots are arranged in pages, how graphical lcd is initialized(Graphical Lcd initializing commands), each and every pin of graphical lcd is deeply explained in the tutorial. You can easily understand the code below if you go through the tutorial. 

Graphical Lcd Pin Out and Working

​Projects Requirements

  • Microcontroller(Microchip Pic16f877)
  • Graphical Lcd(JHD12864E)
  • Crystal (20MHZ)
  • Capacitors (30pf)
  • Potentiometer-Variable resistor(0-100k)
  • Connecting Wires
  • Power Source (Battery, Adapter etc)

Graphical Lcd which i am using is JHD12864E. It comes in 20 Pin Package. Pin out of JHD12864E is given below. Its an 8-bit lcd. It comes with two built in controllers. Each controller is selected with chip select pins (cs1 and cs2). ​Visit the tutorial link given above to properly understand the pin functions and how to use them properly.

JHD12864E(GLCD-Graphical Lcd) Lcd pinout

Graphical lcd with pic microcontroller – Project Circuit Diagram

Lcd data pins are connected to Port-B of pic16f877 microcontroller. Lcd is interfaced in 8-bit mode with microcontroller. RS(register select) Pin of Lcd is connected to Port-D pin#7. RW(Read/Write) Pin of Lcd is connected to Port-D Pin#6. EN(Enable) Pin of Lcd is Connected to Port-D pin#5. CS1(Chip select) Pin of Lcd is connected to Port-D pin#4. CS2(Chip select) of lcd is connected to Port-C pin#4. RST(Reset) pin of Lcd is Connected to Port-D pin#2. A variable resistor is used between pins VEE and V0. This variable resistor is very important, it sets the Lcd contrast. Just connect the resistor, vary the resistance by rotating the knob, Adjust the best quality of lcd display that suites you. You can view highly black colour dots by increasing the resistance. If you want to see fant text reduce the resistance. LED+ and LED- are back light pins. I usually switch on the back light same i did for this project.


All other connections are necessary connections to make controller work. Attach crystal(20Mhz) to controller in parallel to two 30pf capacitors. Supply +5v to vcc and vdd. Make GND ground. Circuit diagram of the project is give below.

JHD12864E Graphical lcd interfacing with Pic16f877 Microcontroller

Coming to code portion. I write code in c++ language and used MPLAB-IDE with High Tech C compiler to compile code and generate Hex code.

  • Clearlcd() function is half-filling each page with dots. Both halfs pages are filled in up and down position. If 2nd page of 1rst half is filled from down then 2nd page of 2nd half is filled from up.
  • #define statements are defining pins as rs,rw,en etc. Now these pins can be accessed in code as rs,rw,en etc.
  • delay() function is used to generate some delay where required.
  • lcdcmd() is sending commands to lcd. It also manipulates lcd pins to successfully execute the command.
  • lcddata() is sending data to lcd. It also manipulates lcd pins to successfully display data on lcd.

Main() function contains the code that displays all stuff on lcd. First it jumps to clearLcd() function fills pages with dots. Then it displays my web site name on lcd. Pattern of each character of my site is commented in the code.

Source: Interfacing Graphical LCD(GLCD-JHD12864E) with Microchip PIC16f877 Microcontroller

Current Project / Post can also be found using:

  • gRAPHICAL lcd with microchip
  • libreria jhd12864e picc

Leave a Comment

= 3 + 1

Read previous post:
Materials that will bring better Aluminium batteries
Materials that will bring better Aluminium batteries

Giant Strides have been moving towards research and production of aluminum batteries. Different teams are working hard to ensure the...

Scroll to top