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.
The project can be downloaded here:
Import programTextLCD
Bar graph simulation with custom characters
Project Pin-out
MBED | LCD | Slider |
---|---|---|
GND | GND | GND |
5V | VCC | VCC |
GND via 1k resistor | VO | n/c |
P13 | RS | n/c |
GND | RW | n/c |
P16 | E | n/c |
n/c | D0 | n/c |
n/c | D1 | n/c |
n/c | D2 | n/c |
n/c | D3 | n/c |
P17 | D4 | n/c |
P18 | D5 | n/c |
P19 | D6 | n/c |
P20 | D7 | n/c |
P15 | n/c | AnalogIn |
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.