Ads

Get STM32 tutorial using HAL at $10 for a limited time!

Saturday, December 19, 2015

LCD 16x2 HD44780 Tutorial 5 - Create Custom Character

In this tutorial, I will share how to create and display custom characters on LCD 16x2. First thing you must know is that on the LCD 16x2 there are two memories that storing 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 'A' character. 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 stored in CGRAM can be accessed from code 0x00 to 0x07.

This table below show character codes and character patterns for CGRAM and CGROM:


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


0x40 is the first address of CGRAM. Every 1 custom character needs 8 CGRAM locations, because the dot format of LCD is 5x8. Every 1 CGRAM location is storing 1 row of 5x8 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 will increase automatically. On the picture below illustrated how the custom characters pattern stored in CGRAM.


The procedure how to define custom character on 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 on CGROM (by calling their codes). The code for custom character that stored on CGRAM is 0x00 to 0x07.

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 display the first custom character).
The result will look like this:

1 comment :

  1. Hi, do you know how to change the position of letters in the character set in the Display? If you have any idea, let us know reparaturservice-hamburg@web.de we pay for it.

    ReplyDelete