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.
What is CG-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
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.
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
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.