I have written a working LCD driver for a NHD‐0212WH‐ATGH‐JT and I would like to add the possibility to create your own custom characters.
Through some research I understood that I need to write a byte for each row in the CGRAM in specific positions and then point to that position when trying to write a character.
I did the following but it doesn't seem to be working:
The array of char for the bytes to write to CGRAM were obtained with online tools such as HD44780 LCD User-Defined Graphics. The functions and commands don't seem to be the problem as I write every other ASCII characters just fine.
char myCustomCharacter[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
void createCharacter(unsigned char location, unsigned char[] bytes){
writeCommand(0x40+(location*8));
writeData(bytes[0]);
writeData(bytes[1]);
writeData(bytes[2]);
writeData(bytes[3]);
writeData(bytes[4]);
writeData(bytes[5]);
writeData(bytes[6]);
writeData(bytes[7]);
}
Then in some test main:
int main(void){
initLCD();
createCharacter(1, myCustomCharacter);
setCursor(0, 0);
writeCharacter('A'); //This work just fine, the A is displayed as expected
writeCharacter(0x08); //Doesn't work, I don't see the character I stored in the CGRAM at the 1st position. Any standard ASCII character still works just fine.
}
How do I access the custom character as if it was just another ASCII character and how do I know I have correctly written the byte into the CGRAM?
Best Answer
The following line adds a custom character to a CGRAM location
1
.The problem with your code was that you told the controller to write a custom character stored at location
8
. The writing code should instead look like this.