Custom Characters on TextLCD

This project demos how to create any 5x8 character on the HD44780 LCD.

Creating Your Character

The values used to create custom characters on the HD44780 LCD can all be generated here: http://www.quinapalus.com/hd44780udg.html

Draw your 7x5 or 8x5 character and save the hexadecimal values as printed. Store these numbers as a static character pointer inside your code.

My Custom Characters (Up to 8)

char custom_char[8][8] = {
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}, // 0
    {0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1f}, // 1
    {0x00,0x00,0x00,0x00,0x00,0x00,0x1f,0x1f}, // 2
    {0x00,0x00,0x00,0x00,0x00,0x1f,0x1f,0x1f}, // 3
    {0x00,0x00,0x00,0x00,0x1f,0x1f,0x1f,0x1f}, // 4
    {0x00,0x00,0x00,0x1f,0x1f,0x1f,0x1f,0x1f}, // 5
    {0x00,0x00,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f}, // 6
    {0x00,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f,0x1f}  // 7
};

Example Simulation

In this simulation, the analog input Phidgets slider was used to demo a bar graph. As the slider increases and decreases in voltage, the LCD shows a bar which fluctuates accordingly. The voltage is represented in any of 7 different states and can be applied to as many analog inputs as desired. The four LED lights on the mbed are used as another method of simulating the bar graph, to confirm the accuracy of the LCD characters.

/media/uploads/gauyeung3/20130307_122101.jpg

The project can be downloaded here:

Import programTextLCD

Bar graph simulation with custom characters

Project Pin-out

MBEDLCDSlider
GNDGNDGND
5VVCCVCC
GND via 1k resistorVOn/c
P13RSn/c
GNDRWn/c
P16En/c
n/cD0n/c
n/cD1n/c
n/cD2n/c
n/cD3n/c
P17D4n/c
P18D5n/c
P19D6n/c
P20D7n/c
P15n/cAnalogIn

Methodology

The characters can be written to the LCD using the built in CGRAM address. To do this, the write port needs to be established like so.

Establishing the Write Port

void writePort(int value) {

    Lcd_pins = value >> 4;  // Shifts 4 bit right.
    wait(0.000040f); // Delay
    e_pin = 0;
    wait(0.000040f);
    e_pin = 1;
    Lcd_pins = value;
    wait(0.000040f);
    e_pin = 0;
    wait(0.000040f);
    e_pin = 1;
}

After the port is established, characters can be written onto the device one at a time using the hexadecimal values saved earlier.

Writing the Characters

for (int j=0; j<8; j++) {

        rs_pin = 0; // Send command

        /* 0X40 is the initial CGRAM address. Because each character needs a total amount of 8 memory 
        locations, we increment addres in 8 units after each character.
        */
        writePort(0x40+8*j);
// Writes custom characters to the text LCD.
        rs_pin = 1; // Send the data here
        for (int i=0; i<8; i++) {
            writePort(custom_char[j][i]);
        }
    }
   

Then print your characters using putc and indexes 0-8.

Links for external documentation and libraries

Text LCD: https://mbed.org/cookbook/Text-LCD

Custom Characters Method: http://mbed.org/users/lnadal/code/Lcd_Custom_Char/docs/639529b48adf/main_8cpp_source.html

Video Demonstration


Please log in to post comments.