You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+109Lines changed: 109 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -117,3 +117,112 @@ and thought I would include it here, since it's related to the LCDs these driver
117
117
118
118
The circuit allows for digitally controlling the contrast via PWM and also controlling
119
119
the backlight brightness via PWM.
120
+
121
+
Custom characters
122
+
=================
123
+
124
+
The HD44780 displays come with 3 possible CGROM font sets. Japanese, European and Custom.
125
+
Test which you have using:
126
+
127
+
```
128
+
lcd.putchar(chr(247))
129
+
```
130
+
131
+
If you see Pi (π), you have a Japanese A00 ROM.
132
+
If you see a division sign (÷), you have a European A02 ROM.
133
+
134
+
Characters match ASCII characters in range 32-127 (0x20-0x7F) with a few exceptions:
135
+
136
+
* 0x5C is a Yen symbol instead of backslash
137
+
* 0x7E is a right arrow instead of tilde
138
+
* 0x7F is a left arrow instead of delete
139
+
140
+
Only the ASCII characters are common between the two ROMs 32-125 (0x20-0x7D)
141
+
Refer to the HD44780 datasheet for the table of characters.
142
+
143
+
The first 8 characters are CGRAM or character-generator RAM.
144
+
You can specify any pattern for these characters.
145
+
146
+
To design a custom character, start by drawing a 5x8 grid.
147
+
I use dots and hashes as it's a lot easier to read than 1s and 0s.
148
+
Draw pixels by replacing dots with hashes.
149
+
Where possible, leave the bottom row unpopulated as it may be occupied by the underline cursor.
150
+
151
+
Happy Face (where .=0, #=1)
152
+
153
+
```
154
+
.....
155
+
.#.#.
156
+
.....
157
+
..#..
158
+
.....
159
+
#...#
160
+
.###.
161
+
.....
162
+
```
163
+
164
+
To convert this into a bytearray for the custom_char() method, you need to add each row of 5 pixels to least significant bits of a byte (the right side).
165
+
166
+
```
167
+
Happy Face (where .=0, #=1)
168
+
..... == 0b00000 == 0x00
169
+
.#.#. == 0b01010 == 0x0A
170
+
..... == 0b00000 == 0x00
171
+
..#.. == 0b00100 == 0x04
172
+
..... == 0b00000 == 0x00
173
+
#...# == 0b10001 == 0x11
174
+
.###. == 0b01110 == 0x0E
175
+
..... == 0b00000 == 0x00
176
+
```
177
+
178
+
Next, add each byte from top to bottom to a new byte array and pass to custom_char() with location 0-7.
`custom_char()` does not print anything to the display. It only updates the CGRAM.
186
+
To display the custom characters, use putchar() with chr(0) through chr(7).
187
+
188
+
```
189
+
lcd.putchar(chr(0))
190
+
lcd.putchar(b'\x00')
191
+
```
192
+
193
+
Characters are displayed by reference.
194
+
Once you have printed a custom character to the lcd, you can overwrite the custom character and all visible instances will also update.
195
+
This is useful for drawing animations and graphs, as you only need to print the characters once and then can simply modify the custom characters in CGRAM.
0 commit comments