Leave Your Message

Name*

Phone number*

Email Address*

Country*

Message*

Annual Quantity*

Application*

How to display custom characters on LCD?
Knowledge

How to display custom characters on LCD?

2025-11-19

In embedded systems and smart devices, the liquid crystal display (Lcd) is a core interactive component. Besides standard ASCII characters, the demand for displaying custom icons and special symbols is increasingly common, making mastering LCD custom character technology a fundamental skill for embedded development. This technology requires combining LCD hardware characteristics with software programming to achieve a complete process from dot matrix encoding to screen display.

 

Core Prerequisite: Understanding the LCD's Character Display Logic

 

To implement custom characters, it's essential to understand the display mechanism of a character-type LCD (such as the 1602 Lcd). Its control chip (typically the HD44780) has a built-in character generator ROM (CGROM), which pre-stores standard ASCII characters. Sending ASCII codes calls the display.

 

Since the CGROM content is fixed, a read-write character generator RAM (CGRAM) is needed to store the custom dot matrix data. CGRAM is typically 64 bytes, divided into groups of 8 bytes, capable of storing eight 8×8 dot matrix characters; LCDs supporting 16×8 dot matrices use 16 bytes per group, storing four characters. The core of custom display is writing the dot matrix data into the CGRAM and then calling it through the CGRAM address.

 

The HD44780 controller's CGRAM address starts at 0x40, with each 8-byte group corresponding to a character identifier: the first character corresponds to 0x00, the second to 0x01, and so on up to the seventh character, which corresponds to 0x07. This is the key basis for code calls.

 

Key Steps: Custom Character Dot Matrix Encoding and Storage

 

The first step in custom display is dot matrix encoding: converting the graphic into binary data recognizable by the LCD. In an 8×8 dot matrix, each character consists of 8 rows, with 1 byte controlling 8 pixels in one row (1 on, 0 off).

 

Taking the "heartbeat" icon as an example, the 8x8 grid is converted row by row into hexadecimal data as follows:

 

- Row 1: Only the middle dot is lit → 00001000 → Hexadecimal 0x08

 

- Row 2: The middle three dots are lit → 00011100 → Hexadecimal 0x1C

 

- Row 3: The middle five dots are lit → 00111110 → Hexadecimal 0x3E

 

- Row 4: The middle three dots are lit → 00011100 → Hexadecimal 0x1C

 

- Row 5: The middle dot is lit → 00001000 → Hexadecimal 0x08

 

- Row 6: All dots are off → 00000000 → Hexadecimal 0x00

 

- Row 7: All dots are off → 00000000 → Hexadecimal 0x00

 

- Row 8: All dots are off → 00000000 → Hexadecimal 0x00

 

Complex graphics can be generated using tools like LCD Assistant to generate dot matrix data, reducing manual errors.

 

After data generation, a CGRAM address setting command (0x40 + character number × 8) must be sent first, and then the dot matrix data is written byte by byte to complete storage.

 

Practical Application: Code Implementation Based on a 51 Microcontroller

 

Taking a 51 microcontroller driving a 1602 LCD as an example, the hardware connection is as follows: the LCD's RS, RW, and E pins are connected to P2.0-P2.2, D0-D7 are connected to port P0, and VEE adjusts the contrast via a potentiometer. The complete implementation code is as follows.

 

  1. Encapsulation of Basic Functions

 

First, encapsulate the basic LCD operation functions:

Encapsulated LCD basic operation functions.png 

 

  1. Custom Character Writing Function

 

A custom character writing function is used to implement dot matrix data storage:

Matrix data storage.png

 

  1. Main Function Call and Display

 

The main function handles initialization, data writing, and display calls:

Initialization, data writing and display calls.png

 

Advanced Techniques and Precautions

 

  1. Dot Matrix Adaptation: 5×10 dot matrix mode (initialization command 0x3C) requires 16 bytes of dot matrix data; the address offset is changed to 16 (0x40 + number × 16).

 

  1. Address Conflict Prevention: Differentiate between CGRAM and DDRAM address commands to avoid display confusion due to accidental operations.

 

  1. Complex Graphics: Large icons such as 16×16 can be achieved by splicing multiple 8×8 characters; precise calculation of partitions and positions is required.

 

  1. Controller Compatibility: Domestic Lcd Controllers may differ; refer to the datasheet to confirm addresses and commands.

 

Application Scenarios and Value

 

Custom character technology is widely used in industrial control (equipment status icons), smart wearables (sports indicators), and home appliances (functional symbols). Its advantages lie in its low storage consumption, fast response, and adaptability to resource-constrained embedded systems.

 

Mastering this technology hinges on understanding the LCD storage mechanism and hardware interface logic. By following the "encoding-writing-calling" process, diverse display needs can be flexibly met, enhancing the device's interactive experience.