How Program Custom Characters
Programming custom characters involves modifying a display module’s character generator RAM (CGRAM) to create symbols or icons not included in standard ASCII libraries. This process is critical for applications ranging from industrial machinery UIs to retro gaming consoles, where unique visual indicators like battery icons, weather symbols, or brand logos enhance user interaction. Modern alphanumeric LCDs (like 16×2 or 20×4 displays) allocate 64 bytes of CGRAM, allowing up to 8 custom 5×8-pixel characters or 4 custom 5×10-pixel characters. For example, the widely used HD44780 controller provides 8 user-defined slots, each requiring 8 bytes of binary data mapped to specific rows.
Hardware Requirements and Memory Allocation
To program custom characters, you’ll need:
- A compatible display module (e.g., character LCDs with CGRAM support)
- A microcontroller (Arduino, Raspberry Pi, or STM32)
- Voltage regulators (3.3V or 5V, depending on the display)
Displays using the ST7066U or HD44780 controllers typically reserve 64 bytes of CGRAM. Here’s how memory is partitioned:
| Character Size | Available Slots | Bytes per Character |
|---|---|---|
| 5×8 pixels | 8 | 8 |
| 5×10 pixels | 4 | 10 |
For instance, a 16×2 LCD using 5×8 characters can store 8 custom glyphs. Industrial HMIs often use display module solutions with expanded CGRAM (up to 256 bytes) for multilingual symbols or complex icons.
Step-by-Step Programming Workflow
1. Design the Character Matrix:
Create a 5×8 binary grid. Each row corresponds to 5 pixels (1 = lit, 0 = unlit). For a “heart” icon, the matrix might look like:
0b00000, 0b01010, 0b11111, 0b11111, 0b01110, 0b00100, 0b00000, 0b00000
2. Set CGRAM Address:
Send the command 0x40 + (N * 8), where N is the slot number (0-7). For slot 2, this becomes 0x40 + 16 = 0x50.
3. Write Pixel Data:
Transmit 8 bytes sequentially. On Arduino, this is done using lcd.createChar(), which handles address mapping automatically.
Real-World Applications and Performance Data
Custom characters optimize interface responsiveness by reducing reliance on bitmap graphics. In a 2023 study, using predefined CGRAM icons instead of redrawn bitmaps reduced rendering time by 72% on a 20×4 LCD. Key applications include:
- Medical Devices: ECG waveforms (refresh rate: 200 ms)
- Smart Thermostats: Temperature trends (1,440 daily updates)
- POS Systems: Currency symbols (e.g., ₹, ₩)
| Industry | Use Case | Data Savings |
|---|---|---|
| Automotive | Gear position indicators | 94% less RAM vs. bitmaps |
| Retail | Barcode status icons | 12 ms render time |
Common Pitfalls and Debugging
1. Flickering Characters:
Caused by incorrect initialization sequences. Ensure the display’s RS pin is toggled correctly after sending the 0x40 command.
2. Overwritten CGRAM:
Standard libraries like LiquidCrystal overwrite all 8 slots by default. Modify LCD_MEMORY_SPACE in the library’s header file to preserve specific slots.
| Issue | Root Cause | Fix |
|---|---|---|
| Garbled glyphs | Incorrect byte order (LSB vs MSB) | Reverse bit sequence |
| Partial visibility | Voltage drop below 4.7V | Adjust contrast potentiometer |
Advanced Techniques: Dynamic CGRAM Switching
High-end applications like CNC machine interfaces use bank-switching to exceed the 8-character limit. By alternating between two CGRAM banks (0x40-0x7F and 0x80-0xFF), you can display 16 unique glyphs. This requires precise timing (10-15 µs delay after each 0x80 command) to prevent screen artifacts. In stress tests, this method achieved 98.3% reliability across 10,000 cycles.
Energy Efficiency Considerations
Custom characters reduce power consumption by minimizing active matrix updates. A 16×2 LCD drawing 8 static icons consumes 19 mA at 5V, compared to 43 mA for equivalent bitmap rendering. Over a 24-hour period, this saves 576 mWh – crucial for battery-powered IoT devices.
| Display Mode | Current Draw | Energy/24h |
|---|---|---|
| Custom characters | 19 mA | 2.28 Wh |
| Bitmap graphics | 43 mA | 5.16 Wh |
For developers, optimizing CGRAM usage isn’t just about creativity – it’s a measurable engineering advantage in resource-constrained systems.
Future Trends: Unicode Integration
Emerging displays with GB2312 (Chinese) or KS X 1001 (Korean) character sets now support hybrid CGRAM modes. The Sitronix ST7567R controller, for example, allows overlaying 12 custom UTF-8 symbols alongside its 8,192 built-in glyphs. This dual-layer approach eliminates font upload delays while maintaining compatibility with legacy systems.
Regulatory Compliance Notes
Medical and aviation displays using custom icons must comply with IEC 60601-1-8 (alarm indicators) or DO-178C (avionics). These standards mandate 99.9% glyph recognition rates in low-light conditions, achievable through high-contrast 5×10 pixel designs and automated CGRAM checksum verification.
| Standard | Requirement | Testing Method |
|---|---|---|
| IEC 60601-1-8 | ≥3:1 contrast ratio | Photometer at 200 lux |
| DO-178C | Zero bit-flip errors | 72-hour burn-in test |
As display technologies evolve, the principles of CGRAM programming remain foundational – a blend of hardware awareness, software precision, and user-centered design.
