LCD16x2 HD44780 Tutorial 5 – Create Custom Characters

LCD16x2 CGROM and CGRAM

In this tutorial, I will explain how to create and display custom characters on LCD16x2. The first thing you must know is that on the LCD there are two type memories that store defined characters, CGROM and CGRAM. CGROM is used for storing all permanent font that can be displayed by using their ASCII code. For example, if we write 0x41 then on the display will show character ‘A’. CGROM memory is non-volatile and can’t be modified. CGRAM is another memory that can be used for storing user defined characters. This memory is volatile and can be modified any time. This memory can store up to 8 user defined characters. Characters that are stored in CGRAM can be accessed from code 0x00 to 0x07. This table below show character codes and character patterns for CGRAM and CGROM.

Char codes

Define a Custom Character

To define a custom character in CGRAM we must access their CGRAM address location. The command for access CGRAM address is show on picture below.

LCD CGRAM command

0x40 is the first address of CGRAM. Every 1 custom character needs 8 CGRAM locations, because the dot format of LCD is 5×8. Every 1 CGRAM location can store 1 row of 5×8 dot format. So, for the first custom character pattern will be stored from address 0x40 to 0x47. After we write some pattern to CGRAM location, the CGRAM pointer is increased automatically. In the picture below, how the custom character patterns stored in CGRAM is illustrated.

CGRAM

One CGRAM

The procedure how to define a custom character in CGRAM is like this:

  1. Send command: 0x40 (Set pointer to the first CGRAM address).
  2. Send data byte 0: 0x04
  3. Send data byte 1: 0x0E
  4. Send data byte 2: 0x0E
  5. Send data byte 3: 0x0E
  6. Send data byte 4: 0x0E
  7. Send data byte 5: 0x1F
  8. Send data byte 6: 0x04
  9. Send data byte 7: 0x00

To display the custom character that already defined is same like we access permanent characters in CGROM (by calling their codes). The code for custom character that stored in CGRAM is 0x00 to 0x07.

Display a Custom Character

After we define the custom character pattern, then we call that character to be displayed on LCD screen. The procedure how to display custom character that already defined is like this:

  1. Set location of DDRAM where we want to place that custom character. For example, we want to display it at home location, so we send command 0x80.
  2. Send data: 0x00 (0x00 is the code for displaying the first custom character).

This is the result. I made 2 custom characters from alarm and battery.

LCD custom characters

Go to last part of the tutorial.

Share this:

Leave a Reply

Your email address will not be published. Required fields are marked *