LCD module Custom Characters

General discussion relating to the library modules supplied with the compiler

Moderators: David Barker, Jerry Messina

Post Reply
Gunplumber
Posts: 38
Joined: Wed Nov 02, 2022 10:31 am

LCD module Custom Characters

Post by Gunplumber » Fri Sep 08, 2023 7:52 am

Hi Guys

Can someone help with some sample code to print custom characters?
There is a sample in the Help file, but it's overly complicated and not very clear how it works.
I know you have to write a series of bytes who's bit patterns correspond to the 5x8 pixels, but how is this done exactly? And once this but patterns have been written, can that character then be displayed at any character position? Or does the data bytes need to be written each time you want to display that custom character?

Cheers
Lee

Jerry Messina
Swordfish Developer
Posts: 1488
Joined: Fri Jan 30, 2009 6:27 pm
Location: US

Re: LCD module Custom Characters

Post by Jerry Messina » Fri Sep 08, 2023 11:45 am

With the HD44780 you get 8 custom chars.
These chars are displayed when you write character codes 0-7 to the display (DDRAM data), just like you would write ascii text ('1', '2', etc).
Each custom char pattern takes eight bytes of CGRAM data (the dot patterns).

Once you load the CGRAM data with the pattern then whenever you write the char code byte (0-7) to the DDRAM you get the custom pattern displayed at the current char position on the display, so you can write them anywhere on the display just like normal text.

Code: Select all

include "LCD.bas"

// custom char bitmap data patterns...
// programmable characters are available that use codes $00 to $07 
// each char takes eight bytes
const CGRAM_DATA(64) as byte = 
                          ($01,$01,$01,$01,$01,$01,$01,$00,  // char 0
                           $10,$10,$10,$10,$10,$10,$10,$00,  // char 1
                           $14,$14,$14,$14,$14,$14,$14,$00,  // char 2
                           $15,$15,$15,$15,$15,$15,$15,$00,  // char 3
                           $16,$16,$16,$16,$16,$16,$16,$00,  // char 4
                           $17,$17,$17,$17,$17,$17,$17,$00,  // char 5
                           $18,$18,$18,$18,$18,$18,$18,$00,  // char 6
                           $19,$19,$19,$19,$19,$19,$19,$00)  // char 7

LCD.Initialize()

// init custom char CGRAM data
// this will call the overloaded sub 'Private Sub WriteItem(ByRefConst pBitmap() As Byte)' in LCD.bas to load the bit patterns into CGRAM
LCD.Write(CGRAM_DATA)

// after that, just write chars 0 to 7 like you would ascii text
LCD.Write(0)		// char 0
LCD.Write(1)		// char 1
LCD.Write(7)		// char 7
HD44780U custom char map.jpg
HD44780U custom char map.jpg (82.08 KiB) Viewed 2213 times

Gunplumber
Posts: 38
Joined: Wed Nov 02, 2022 10:31 am

Re: LCD module Custom Characters

Post by Gunplumber » Sat Sep 09, 2023 4:10 am

Hi Jerry

Once again, thanks for the help.. Much appreciated!!
I have the custom characters up and running.. :D

Cheers
Lee

Post Reply