-
Notifications
You must be signed in to change notification settings - Fork 4
5. Custom characters defining and usage
Example of Correspondence between EPROM Address Data and Character Pattern (5 × 8 Dots)
If the letter 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};
HD44780 allows the user to define a maximum of 8 user characters. Therefore on character bank can contain only up to 8 characters. Nevertheless, it's possible to define a couple of special character banks with different combinations of special characters. Depending on needs one of the banks can be loaded to the CGRAM and switched to another if the information presented on the LCD requires different special characters
Below you can find a simple example of two special characters bank definitions:
-
Definition 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};
-
Declaration of lcd_cgram_bank_1 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, };
-
Declaration of lcd_cgram_bank_2 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, };
-
When special characters from bank_1 are needed to display content on an LCD screen, it's required to call in the code:
lcd_load_char_bank(&lcd_cgram_bank_1);
-
When special characters from bank_2 are required to display content on an LCD screen, then it's required to call in code:
lcd_load_char_bank(&lcd_cgram_bank_2);
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);