The 16x2 LCD: Display Custom Characters

Program Download:

Basic Custom Characters
LCD_Custom_Char.c

Animation On The LCD
LCD_Animation.c

The Software
           The software has two main parts that I want to show and explain:
    - Custom Character Array
    - Character Loading and Display



Custom Character Array
           Just as we saw in the theory section of this tutorial, we have to encode the images in binary in order to store them in the LCD module. In the code below, I've shown 3 examples from the software of how images were encoded and stored in the program in order to be loaded into the LCD. Notice the first character is from our example in the theory section.


------------« Begin Code »------------
....
..
//Smiley Face From The Tutorial
unsigned char font_a_char_0[8] = {
0b00000000, // _____
0b00001010, // _*_*_
0b00001010, // _*_*_
0b00001010, // _*_*_
0b00000000, // _____
0b00010001, // *___*
0b00001110, // _***_
0b00000000  // _____
};

//Unused Custom Character
unsigned char font_a_char_1[8] = {
0b00000000, // _____
0b00000000, // _____
0b00000000, // _____
0b00000000, // _____
0b00000000, // _____
0b00000000, // _____
0b00000000, // _____
0b00000000  // _____
};

//Pyro Image #1
unsigned char font_a_char_2[8] = {
0b00001110, // _***_
0b00001011, // _*_**
0b00001001, // _*__*
0b00001000, // _*___
0b00001100, // _**__
0b00000111, // __***
0b00000100, // __*__
0b00001100  // _**__
};
..
....
------------« End Code »------------


Character Loading and Display
           The second code excerpt I want to show is how the encoded data seen and stored in an array above, is loaded into the LCD's CGRAM and then displayed on the LCD. The initial loading of the custom image is done through a for loop and the subsequent display of the character is done the same way any other character is displayed, except the character codes are always 0 to 7. Notice character code 0 (or 0b0000 0000) is the smiley face from the theory section.

------------« Begin Code »------------
//Load Custom Character 0
for(i=0;i<8;i++){
cgram_loc = 0b01000000 + i;
LCD_COMMAND(cgram_loc);
LCD_WRITE(font_a_char_0[i],99);
Delay100TCYx(1);
}

//Load Custom Character 1
for(i=0;i<8;i++){
cgram_loc = 0b01001000 + i;
LCD_COMMAND(cgram_loc);
LCD_WRITE(font_a_char_1[i],99);
Delay100TCYx(1);
}
...
..
//Show Off The Smiley Face
LCD_WRITE(0x00,22);
LCD_WRITE(0x00,23);
LCD_WRITE(0x00,24);
LCD_WRITE(0x00,25);
LCD_WRITE(0x00,26);
..
....
------------« End Code »------------

LCD Animation
           This program goes beyond the scope of this tutorial, but I put it here for the over achievers. Basically I made 7-8 characters (images) that make it 'seem' like there is a smooth movement when the characters are updated on the LCD. The reality is that there is actually a different character for each animation movement. It is possible to generate on-the-fly characters as needed, but the complexity of doing that goes beyond this introductory tutorial.



;