KS0108 Generic Library for PIC18F4550

///KS0108 Generic Library for PIC18F4550
  • KS0108 Generic Library for PIC18F4550

KS0108 Generic Library for PIC18F4550

Samsung KS0108/KS0107 is one of the most popular dot matrix LCD controllers available in the market. They are commonly seen in the graphics LCDs. In this article, we are going to use a universal library available for KS0108 based GLCDs. It supports displays with 128×64 and 192×64 resolutions and can be used with different microcontroller platforms including Microchip PIC microcontrollers.
In our example, we are using JHD12864 graphical LCD. It has a resolution of 128×64 which means that it can display 8192 pixels on the screen. In comparison with the 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 can display on them.

Please refer:

Library Structure

In this example, we are going to implement a custom library for KS0108 based graphics LCDs. The generic library can be downloaded from the link: KS0108 generic library download

Files included in the library are:

  • KS0108.h & KS0108.c – main library file and its header file
  • graphic.c & graphic.h – this contains graphic routines
  • font5x8.h – font definitions for common alphanumeric characters in 5×8 pixel size
  • KS0108-XXXXX.c&.h – Low level driver for different Microcontrollers

The library contains a low-level driver file for PIC16 family, but here we are going to implement it on the PIC18F device (PIC18F4550). So we need to add a separate file named KS0108-PIC18.c (or you may edit that one).

KS0108

This file has the main higher level functions used in our applications. It includes initializing, setting the location, clearing the screen, writing a single character and string, setting a pixel and displaying a bitmap image.

The header file (KS0108.h) also contains some global parameter including screen width, screen height, and commands for various commands. We need to change these values based on our display size. It’s better to refer the datasheet of your display because some displays have inverted pin configurations. But it is rare to have these type of settings changed, so we can go with the default settings.

Graphics and Fonts

The graphics file has three graphics related functions- draw rectangle, circle, and line.

In font5x8, pixel details for all the 95 alphanumerical characters are defined.

KS0108-PIC18

Here, we are going to define the low level (hardware level) details in this file. It includes the pin interfacing details and low-level functions to enable, transfer data and commands, read status and data etc. We need to define different functions to interact PIC microcontroller with the GLCD. These files may not be present in the library as the PIC18F series, which we are using, has only a PIC16 based file. So we will be creating two files, one header file and the source file for this. Declare all the functions in a header file and define it on the source file.

We require timing diagrams for read and write instructions. Please refer the previous article KS0108 based Graphic LCD interfacing with PIC18F4550 – Part 2 for detailed information on implementation.

Initialization and Other Controls

graphic-lcd-interfacing-with-pic18f4550-circuit-diagram

GLCD interfacing with PIC18F4550

The pin level description is given in below section. We need to define data port, a control port, and their direction registers. The control port pin definition has to be done in the individual manner as their order will be different in different modules. In 128×64 resolution controllers, we don’t need the third KS0108 controllers. We keep it defined for avoiding errors, but we won’t be using it on circuits.

Read Data/Status

The timing diagram of read command is as below.

graphic-lcd-read-timing-diagram

Using the timing diagram, we can write the functions for reading status and reading data as follows.

Write Data/command to the GLCD

During the write function, R/W becomes low as given in the timing diagram below. The D/I decides whether it is an instruction or data.

graphic-lcd-write-timing-diagram

The Main Function

Using the above functions, we can write an example code for displaying a string, drawing a circle and drawing a rectangle (in the main file).

The above example is available at our Github repository: https://github.com/etiq/OpenLab-GLCD-example/

DON’T MISS OUT UPDATES!
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

Leave A Comment

DON’T MISS OUT UPDATES!
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.
close-link
25% OFF - OpenLabPro Course
Use Coupon: CRS25UL

 
PIC Microcontroller Primer
Want to learn indepth programming, peripheral interfacing and driver development?
close-link
Launched: IoT online Course - 25% Off when you complete your order today.
Checkout Now
close-image

Subscribe To our Email Newsletter

Be the first to get latest updates and exclusive content straight to your email inbox.
Send me Tutorials and Guides
close-link