How to create custom characters on 16x2 LCD using PIC18F4550

Summary

The 16x2 character LCD can also be used to display custom characters other than numerals, alphabets & special characters. Refer LCD interfacing with PIC. Some special shapes like hearts, arrows, smileys etc. can easily be displayed on the 5x8 pixel pattern of character LCD. These shapes are first stored at a special location in LCD’s controller and then displayed on the LCD module. This procedure has been explained here by using PIC18F4550.

 

Description

 

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.
 
ASCII Code
Base Address
0
64
1
72
2
80
3
88
4
96
5
104
6
112
7
120
 
 
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.
 
 
Programming Steps:
·            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
          while(j<8)
          {
                    lcddata(data[j]);      // sends bitmap values of the character
                    j++;
          }
          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.
 
special_char(64,0x82,value);

 

Circuit Diagram

Video

Code

This Code is only visible to Registered users. Please Login/Register

 

Components

Presets | Variable Resistors
Preset
 
A preset is a three legged electronic component which can be made to offer varying resistance in a circuit. The resistance is varied by adjusting the rotary control over it. The adjustment can be done by using a small screw driver or...
16 x 2 LCD | 16x2 Character LCD Module
LCD

 

LCD (Liquid Crystal Display) screen is an electronic display module and find a wide range of applications. A 16x2 LCD display is very basic module and is very commonly used in various devices and circuits. These modules are preferred over seven segments...

PIC18F4550 Microcontroller Image
PIC18F4550

PIC18F4550 is an 8-bit microcontroller of PIC18 family. PIC18F family is based on 16-bit instruction set architecture. PIC18F4550 consists of 32 KB flash memory, 2 KB SRAM...