The special characters are generated by bit-mapping of LCD’s 5x8 bit pixel matrix. Refer Creating custom characters on LCD using 8051 for more details on bitmap generation and storing custom values in custom generator (CG) RAM of LCD’s controller.
The mikroC IDE provides LCD Custom Character tool to create the bitmap of user defined custom character. (Also see Working with mikroC) To create the bitmaps using this tool, following steps are to be followed:
1. Go to Tools -> LCD Custom Character
2. Select 5x7 + cursor line font and start filling the pixels in the matrix by clicking on them to create a custom character. The following figure depicts the generation of heart shape’s bitmap.
3. After creating the character and click on GENERATE button. A window will appear containing the bitmap values of designed custom character as highlighted in the following figure.
4. These bitmap values can now be used in the code.
The bitmap values of a custom character are stored in CGRAM of LCD controller module. The CGRAM can store up to 8 custom characters’ bitmaps. For more details, refer Custom character display using 8051. The addresses of CGRAM where bitmaps are stored are shown in the following table.
The following programming steps are used to store the bitmap values into CGRAM and display the corresponding custom character on LCD. An example is also given at the end to understand the code and concept.
· Select the base address of CGRAM where the bitmap values are to be stored. This address is sent as command instruction (RS=0).
· After the address, the bitmap values are sent one by one as data (RS=1).
· Next the LCD location is sent where the character is to be displayed.
· The corresponding ASCII value of the base address of the CGRAM is sent to print the stored character. This is sent as data value (RS=1).
The above steps are integrated into a single function special_char() which makes it easier to display the custom characters on LCD.
void special_char(unsigned char cgram_loc, unsigned char lcd_loc, unsigned char *data)
unsigned int j=0;
lcdcmd(cgram_loc); // sends location of CGRAM
lcddata(data[j]); // sends bitmap values of the character
lcdcmd(lcd_loc); // sends LCD location where the character is to displayed
lcddata((cgram_loc-64)/8); //ASCII value of corresponding base address.
If a data array value (containing bitmap values) is to be stored at CGRAM location 64 (base address), and is to be displayed at 0x82 location on LCD (i.e., first line, third column); then the above function is called as follows.