This tutorial is about making/building your own characters/special images and then displaying them on character 16×2 lcd. Generating custom characters or special character images and displaying on lcds of any sizes (16×1,16×2,8×1,8×2,20×1,20×2,40×1,40×2 etc) is not a very hard task. One must go through the internal structure of lcd control set in order to know how the character lcd works? Once you know how the lcd works and what features it offers. Then you can easily build and display characters of your desire on lcd screen in a defined matrix.
It requires only knowledge of CG-RAM(character generated ram) of character lcd and the lcd chip set controller to build and display self made characters on 16×2 lcd display. Most of the lcds contains HD4478 controller in them. HD4478 controller is build by Hitachi and its the most popular controller used in the character lcd’s. Almost all of the character lcd’s resides one, but new competitors are also present in market.
By custom characters i mean characters that are not present in the ASCII character set of lcd controller. Like heart symbol, smiley 😀 🙁 ;D :-d 😉 etc. We have to declare these custom characters in CG-RAM of lcd by our own. This tutorial will teach you how to declare custom characters in CG-RAM and then call display them one by one to display on 16×2 lcd screen.
CG-RAM is the main component in making custom characters. CG stands for custom generated and RAM you all know random access memory. This CG-RAM stores our custom characters once we declare them in our code. I will come on it later. As you know once we write any type of code we need a memory to store it and a controller to run it. In the 16×2 lcd custom character case its same. We write code(arrays) of character’s which we want to display on lcd. Then we store them in a memory on lcd. In our case this memory is named as CG-RAM(Character generated RAM).
CG-RAM size is 64 Bytes. You can create 8 characters at a time and load them in cg-ram. Each character occupies 8-bytes. Eight characters each of eight byte (8-characters * 8-Bytes) is equal to 8×8=64 Bytes. CG-RAM address in lcd memory starts from 0x40(Hexadecimal) or 64 in decimal.
You can place your first character in address ranging from 0x40 to 0x47. The address moves on by 8 bytes for each character for 2nd character address starts from 0x48 and goes to 0x4F. Last eight’t character address starts from 0x78 and goes to 0x7F.
We generate and put our self made custom characters at these addresses. Once we generate our characters at these address now we can print them on lcd at any time by just sending simple commands to lcd controller. Below is the table in which characters addresses and their printing commands are given.
How to Generate and place Custom Characters in CG-RAM?
Declaring character bits against CG-RAM addresses
Here is a simple example on how to generate pixels array for letter ‘b‘ and then place it in CG-RAM of character 16×2 lcd display.
The Array for generating letter ‘b‘ is
We now have some online websites through which you can get array of your desired image in 5×7 or 5×8 format. One of the most popular is maxpromer. You can graphically input your desired image on a matrix in maxpromer and then with a single button press you get the array of the image. The array can further be used in your code.
In the above picture you can see the interface of maxpromer. Pretty simple and easy to use. In just seconds you can generate the matrix array for your input character. Array can be generated in binary as well as hexadecimal format.
What individual bits represent in array really needs to be understood. ‘0‘ represents pixel is off and ‘1‘ represent pixel is on. Like for the letter ‘b‘ whose array was highlighted above. Its representation is given below. For each row we have a binary or hexadecimal representation. In binary representation we ignore the 3 MSB or most significant bits, because the coulombs of the matrix are 5. So 5 LSB least significant bits are considered. Also in hexadecimal representation the 3 MSB don’t matter. In the below picture the array of letter ‘b‘ is placed against address ranging from 0x40 to 0x47. Row-1 is placed at address 0x40, row-2 is placed at 0x41, then row-3 is placed at 0x42 and so on until row-7 against address 0x47.
Sample c++ code to generate custom character in cg-ram
The above task is just a simple demo. We properly have to select the data and command registers of lcd in order to place the custom image in CG-RAM.
Important: Just to let you know that commands(like 0x40 address of cg-ram) are send to command register of lcd and data like ‘b‘ pattern is send to data register of lcd.
The above code can be divide in to steps
- Send cg-ram character starting address where you want to create character. I send 0x40 in the above code which means i am placing character in first location.
- Now put your character at this address. Send the ‘b‘ character array string defined above one by one to data register of lcd.
- To print the generated character at 0x40. Send command 0 to command register of lcd.
Visit some projects which i created using different microcontrollers to display custom self made characters on lcd screen. These projects will help you to understand what command and data registers means and how to select them? Projects contains free source code and circuit diagrams.
Filed Under: Featured Contributions
Tagged With: 16x2 LCD, address, CG-RAM, display, lcd