A graphical LCD is an electronic display unit which can display any type of elements provided by the user. Unlike a character LCD which can only display alphanumeric characters, a graphical LCD can display images, fonts and other structures. This article gives details of graphic LCD interfacing with a PIC microcontroller.
JHD12864 graphical LCD has a resolution of 128×64 which means that it can display 8192 pixels on the screen. In comparison with character LCD, it can display anything on the screen provided by the user. Character LCD only displays the alphanumerical characters. The user can create images, fonts and other structures and display on them. It uses KS0108 display controllers for controlling LCD panels on the GLCD.
KS0108 is a dot matrix display controller from Samsung with 64 channel output. It receives input as 8-bit parallel data and stores in data RAM which has a capacity of 512 bytes (512×8 = 4096 bits). To drive 128×64 graphic display, we will need two of these controllers and each will be controlling a half of 64×64 pixels. To generate timing signals for these two controllers, there is a common driver KS0107. There are also other display controllers for graphic LCD, an example is Toshiba T6963C. But we will be discussing about KS0108 based graphic LCD interfacing in this article.
JHD12864 is a 20-pin GLCD module. It has 8 data lines, 6 control lines and 6 power and display related pins. Pin descriptions are given below.
The GLCD module’s pins from 7 to 14 are data pins. We use these pins to transfer the data to the display RAM.
1 and 2 pins are Vdd and Vss pins. Connect these pins to 5V and ground respectively.
The pin 18 is the output of a negative voltage generator. It generates -10V in the case of JHD12864 GLCD module. By using a potentiometer, we can generate the required operating voltage by feeding the negative voltage to the Vo pin. The resulting LCD voltage will be Vdd-Vo (If the pot is in minimum, 5-(-10) = 15V). From the datasheet of JHD12864 module, the maximum LCD voltage allowed is 18V. We can vary Vo to change the contrast of the display.
The 19 and 20 pins are Anode and cathode of backlit LED, limit the current through it by putting a resistor in the line. We can use a pot if you need to vary this too.
CS1 and CS2 pins are used to select the KS0108 controller from the two. CS1 selects the left side controller and CS2 selects the right one which in turn selects the corresponding side of the displays 64×64 pixels. RST is the reset pin, it is used to reset the entire display content by clearing whole of the display RAM. R/W pin selects the type of operation being performed by the GLCD, a High indicates read operation and a Low indicates write operation. Data/Instruction (D/I) selects between data transfer or instruction.
The Enable pin is the clock of GLCD. It is used to clock the data/instruction to the display module. For transferring the data or instruction, first you need to place the data on the data lines, then pull R/W and D/I High or Low according to the type of instruction and then set the Enable pin Low and then a High in order to transfer the data. One of the important consideration while clocking is, always give at least 1 microsecond delay after every instruction or data transfer. This parameter will be defined as Ecycle in the datasheet of the module. For JHD12864, the Ecycle value is 1us.
There are 4 modes of operation based on the values of D/I and R/W.
Graphical LCD block diagram is given below, it has two KS0108 segment drivers and a KS0107 common driver. KS0108 is a dot matrix LCD segment driver with 64 channel output which maintains one half of the GLCD. KS0107 is a 64 channel common driver which generates timing signals to control the other two KS0108 segment drivers.
There is also a negative voltage generator which outputs the negative voltage through Vee pin. In some display modules, this section may not be present. So we will need to generate the negative voltage from outside. In some GLCD displays, the segment and common drivers used will be made by different manufacturer, but they will be compatible with KS0108 controllers.
Translating inputs on the screen
Each KS0108 controls half of 128×64, that is 64×64 pixels. To select the one half, make the chip select pin low while making the other’s pin high. There are 8 pages in each half which is controlled by each KS0108 controller. One page (one row) contains 64 columns of 8 rows. Whenever we transfer the data, we first selects the half by CS bits, then page address (X) and then the Y address. The byte will be transferred as a 1 bit wide strip and will be stored in display RAM location. We can summarise this process as follows.
- CS1 and CS2 select the half (64×64 pixels)
- Page select will narrow it down to 64×8 pixels (64 vertical strips of 8 pixels each)
- Y address will select the correct vertical 8-pixel strip
Take an example of displaying ‘P’ in the first line of GLCD. We are making a font of size 5×7 pixels. We will be leaving first two columns, 8th column and last row of the page for spacing. These fonts are called 5×7 fonts. Below image explains how the fonts are created in graphic LCDs.
In order to display this, we need to transfer following bytes to the first page of the display by selecting left controller (CS1) in Y address from 0 to 7: 0x00, 0x00, 0x7F, 0x09, 0x09,0x09,0x06,0x00.
There are seven instructions available in KS0108 controller and are given in the below table.
The above table lists different instructions available for KS0108 controller. For example, to turn the display ON, make RS and R/W Low, put 00111111 in DB7-DB0 pins and clock it by making enable pin Low to High. We will be discussing each of the instructions and implementation in the next part of this article.
Circuit diagram: Interfacing Graphical LCD with PIC18F4550
To interface the graphical LCD, we need one 8-bit port and 6 other pins. We may avoid using RST pin, but we will need to ground it for using the LCD. Below is the circuit diagram of GLCD interfacing with PIC18F4550. We have used a 1K resistor to limit the current to the backlit LED.
We will discuss the different instructions and firmware implementation in next part of this article.