-
Notifications
You must be signed in to change notification settings - Fork 1
5. Custom characters defining and usage
Example of Correspondence between HD44780 EPROM Address Data and Character Pattern (5 × 8 Dots)
If the character shown in the picture above should be defined as a special character, its definition should look like this:
static const uint8_t leter_b[8] = {16, 16, 22, 25, 17, 17, 30, 0};
The HD44780 LCD controller allows the user to define up to 8 custom characters in its CGRAM (Character Generator RAM). Sometimes, these 8 characters are insufficient for the entire application's needs but may suffice for specific parts of the functionality. By loading 8 custom characters and then reloading them with different characters at different points in the code, this limitation can be managed effectively.
A character bank is a collection of up to 8 custom characters. While each bank can contain only 8 characters, multiple-character banks can be defined with different combinations of custom characters. Depending on the requirements, one of these banks can be loaded into the CGRAM and switched to another bank as needed, ensuring that the LCDs the appropriate special characters for various parts of the application.
Below you can find a simple example of two special character bank definitions. This example includes the initialization of 10 special characters, the setup of 2 character bank structures, and an enumeration definition containing labels for each character position in the character bank.
-
Initialization of special characters in lcd_hd44780_def_char.h:
static const uint8_t Pol_e[8] = {0, 0, 14, 17, 31, 16, 14, 3}; static const uint8_t Pol_o[8] = {2, 4, 14, 17, 17, 17, 14, 0}; static const uint8_t Pol_s[8] = {2, 4, 14, 16, 14, 1, 30, 0}; static const uint8_t Pol_l[8] = {12, 4, 6, 12, 4, 4, 14, 0}; static const uint8_t Pol_c[8] = {2, 4, 14, 16, 16, 17, 14, 0}; static const uint8_t Pol_a[8] = {0, 0, 14, 1, 15, 17, 15, 3}; static const uint8_t Pol_n[8] = {2, 4, 22, 25, 17, 17, 17, 0}; static const uint8_t Zn_wody[8] = {0, 0, 0, 6, 9, 2, 4, 15}; static const uint8_t Pol_z1[8] = {4, 32, 31, 2, 4, 8, 31, 0}; static const uint8_t Pol_z2[8] = {2, 4, 31, 2, 4, 8, 31, 0};
-
Initialization of lcd_cgram_bank_1 and definition of the char bank 1 char position labels in lcd_hd44780_def_char.h:
static const struct char_bank_struct lcd_cgram_bank_1 = { Pol_e, Pol_o, Pol_s, Pol_l, Pol_c, Pol_a, Pol_n, Zn_wody }; enum LCD_CGRAM_BANK_1 { pol_e, pol_o, pol_s, pol_l, pol_c, pol_a, pol_n, zn_wody, };
-
Initialization of lcd_cgram_bank_2 and definition of the char bank 2 char position labels in lcd_hd44780_def_char.h:
static const struct char_bank_struct lcd_cgram_bank_1 = { Pol_e, Pol_o, Pol_s, Pol_l, Pol_c, Pol_a, Pol_z1, Pol_z2 }; enum LCD_CGRAM_BANK_1 { pol_e, pol_o, pol_s, pol_l, pol_c, pol_a, pol_z1, pol_z2, };
To print on LCD any user character:
- A special characters bank with the character that you would like to print need to be loaded.
For example:lcd_load_char_bank(&lcd_cgram_bank_1);
- The lcd_char or lcd_buf_char function need to be called. For example
lcd_char(zn_wody);