The 128×64 GLCD can be used to display text, logos, graphs, shapes and other useful bit images. To interface the GLCD with the LPC1768, we need 8 data pins and 6 control pins. In this tutorial, we will be using the KS0108 GLCD library from http://en.radzio.dxp.pl/ks0108/.
We will be discussing how to develop a program to run this library.
- The 128×64 GLCD contains 8 data pins.
- There are 6 control pins of which 3 are similar to the ones used for the 16×2 character LCD; En-Enable, R/W-Read/Write Bit and the RS-Register Select bit.
- A fourth pin is the RST or the reset pin used for resetting the module. (This is commonly known as CS3 or chip select 3)
- Finally, we have the chip select pins of the internal controller CS1 and CS2.
- DEFINITIONS: We will be using the KS0108-LPC.c file that is used for the low-level driver for NXP LPC2000 ARM-core MCU.
Since we are using a different controller, a few modifications have been made in the definition of this file alone in order for it to be compatible while using the LPC1768 MCU and our OpenLab platform.
The definitions have been modified in such a way that we will be using pins from 16 to 23 of PORT0 as data pins and pins 16 to 21 of PORT1 as control pins. The modified definitions have been given below.
// data bus #define KS0108_DATA_DIR LPC_GPIO0->FIODIR #define KS0108_DATA_PIN LPC_GPIO0->FIOPIN #define KS0108_DATA_SET LPC_GPIO0->FIOSET #define KS0108_DATA_CLR LPC_GPIO0->FIOCLR #define KS0108_D0 16 // control bus #define KS0108_CTRL_DIR LPC_GPIO1->FIODIR #define KS0108_CTRL_SET LPC_GPIO1->FIOSET #define KS0108_CTRL_CLR LPC_GPIO1->FIOCLR #define KS0108_RS (1 << 18) #define KS0108_RW (1 << 17) #define KS0108_EN (1 << 16) #define KS0108_CS1 (1 << 20) #define KS0108_CS2 (1 << 19) #define KS0108_CS3 (0 << 21) #define DISPLAY_STATUS_BUSY 0x80
- INITIALIZATION: Include all the necessary header files and then start by initializing the GLCD using the function GLCD_Initalize().
- DISPLAYING SHAPES: First, we will be displaying a few shapes and for that, we will be using the graphics.c library file from the same link given above. Using the GLCD_Rectangle() and GLCD_Circle(), we will be drawing a two-dimensional rectangle and circle on the screen.
The GLCD_Rectangle() takes four function parameters. The first two parameters indicate the starting position from where the rectangle must be drawn (Top left corner of the rectangle). The next two parameters define the length and breadth of the rectangle.
The GLCD_Circle() takes three function parameters. The first two parameters indicate the position of the circle and the third parameter defines the radius of the circle.
- The ClearScreen and GoTo functions are utility functions. ClearScreen helps in clearing all the data that is displayed on the GLCD screen and the GoTo function helps to get to a particular location of the screen.
- DISPLAYING TEXT: The text is displayed using the GLCD_WriteString function. For each character in a text, the 5×8 matrix two-dimensional data is stored in a one-dimensional array in the font5x8.h header file. This memory is accessed every time we try to write a text or a character.
- DISPLAYING LOGO: Next we display a logo. It takes 5 function parameters. The first parameter is the logo data stored in the form of a one-dimensional array. The next two parameters determine the position of the logo and the final two parameters define the length and breadth of the logo. Any type of logo can be converted to its bitmap using the application in this link http://en.radzio.dxp.pl/bitmap_converter/
We have learned to use the KS0108 driver library from radzio.dxp and created a program to run the library using LPC1768 MCU. The code based on this tutorial is available in the Code Library