In our previous article, we were discussing features, pin diagrams, internal features of the KS0108 controller based GLCDs and graphic LCD interfacing with a microcontroller. In this article, we are discussing the implementation of different instructions.

Instructions in KS0108 Controllers

KS0108 controllers have seven instructions, they are given in the following table.


The enable pin works as a clock for the GLCD. During write instructions, after setting each pin of the corresponding value, enable pin must be applied with a high to low pulse. The data will be latched at the falling edge of the E. For reading instructions, data appears while E is at a high level. Always give a delay of more than Ecycle (refer datasheet of the KS0108) between each instruction and also consider other timing parameters like delay time, rise time and setup time. Refer the timing diagram of write and read cycles in the datasheet.
Another important thing to consider is, most instructions are write instructions and some are in reading mode. So we will need to set the microcontroller port direction accordingly.

Write Command

Below is the write timing diagram of the KS0108 controller. In the diagram, most important characteristics are illustrated. They are Tc (E cycle time), Twl(E Low-level width time), Twh(E High-level width time), Tasu (Address set-up time), Tdhw (Data hold time – write). There are other characteristics like rise time, fall time and address hold time. They are not included in the firmware because they are either covered by other characteristics or they are not that significant. Please refer the KS0108 datasheet for finding out the maximum, minimum and typical values of the timing parameters.

write-timing-diagram - Graphic LCD interfacing

Using the above timing diagram, we can create a common function to write command or data.

Read Command

read-timing-diagram - Graphic LCD interfacing

From the above timing diagram, we can write the function for reading data as below.

KS0108 Instructions

Display On

This is the first and foremost command to set during the initialization. This instruction will turn ON the display. The above command is translated to the code as below.

Set Address (Set Column)

This instruction sets the Y address of the display. If the address is less than 64, it is controlled by left. If it is between 64 and 128, it is on the right controller. So we need to turn ON the correct controller based on the display address.


Set Page (Set Row)

The display pointer can be set to a row with the help of simple instruction. Put the instruction on data port and give a high to low pulse on enable pin.

By combining the above two functions, we can create a function to set the XY position.

Display Start Line

This instruction sets the starting line of the display from the display data RAM. For example, if you want to roll the content, set the start line as first, then set it as second and so on. The viewer will see the content on the display RAM’s first page on the first line, then data from the second page on the first line (after setting it as second using the display start line instruction) and so on. This instruction can be used for animating the content.

Status Read

To check whether the display is busy/ON/reset, we can use the status read instruction. The busy flag indicates the display controller is operating or non-operating mode. If it is high, we need to wait till the flag becomes low.

Below function checks whether the display is in reset condition or OFF. It returns 1 if it is OFF, 2 if it is reset.

Write Display Data

Write display data instruction writes a single byte of data from the data bus into the current address of the display RAM.

Read Display Data

This instruction reads the data from the current address of display RAM.

Other Functions

Other functions that can be derived from the above functions are given below.

Clear line

This function clear a given line.

Clear display

This is for clearing the entire display contents.

Fill Data

This function can be used to fill with same data all over the display.

Display Dot

Below function displays a dot after setting position in x,y format.

Example Code Using Above Functions

Using the above-defined functions, we can write a sample code for a 128×64 display as below. Include above functions in the main file.


Here we are going to display the letter “P” in (0,0) position of the display.

We can create graphics like lines, circles and boxes and different sized fonts in a similar manner. In the next part of the tutorial, we are going to use a generic library which has all the features including graphics, fonts etc.

Be the first to get latest updates and exclusive content straight to your email inbox.
Stay Updated
Subscribe, it is quick.
We hate spam too. Give it a try, you can unsubscribe anytime.
Spread the love, share this