All character based LCD has CGRAM area to create user defined patterns. For making custom patterns we need to write values to the CGRAM area defining which pixel to glow. These values are to be written in the CGRAM address starting from 0X40. If you are wondering why it starts from 0X40? Then the answer is given below.
Bit 7 is 0 and Bit 6 is 1, due to which the CGRAM address command starts from 0X40, where the address of CGRAM (Acg) starts from 0x00. CGRAM has a total of 64 Bytes. When you are using LCD as 5×8 dots in function set then you can define a total of 8 user defined patterns (1 Byte for each row and 8 rows for each pattern), where as when LCD is working in 5×10 dots, you can define 4 user defined patterns.
Lets take an of building a custom pattern. All we have to do is make a pixel-map of 7×5 and get the hex or decimal value or hex value for each row, bit value is 1 if pixel is glowing and bit value is 0 if pixel is off. The final 7 values are loaded to the CGRAM one by one. As I said there are 8 rows for each pattern, so last row is usually left blank (0x00) for the cursor. If you are not using cursor then you can make use of that 8th row also. so you get a bigger pattern.
ASCII Coding
When the ASCII code for any character, say ‘A’, is sent to be displayed on LCD module, the module’s controller looks up the appropriate 5×8-pixel pattern in ROM (read-only memory) and displays that pattern on the LCD. There are only 8 symbol locations where a custom character can be stored as shown in the following right table. These locations will have a particular bitmap layout corresponding to the custom character. To display an arrow sign, the bitmap values are mapped to a base address location, say 64 (ASCII code 0)
The symbol locations with their base addresses are given below:
ASCII Code
|
Base Address
|
0
|
64 (0X40 in hex)
|
1
|
72
|
2
|
80
|
3
|
88
|
4
|
96
|
5
|
104
|
6
|
112
|
7
|
120
|
This is achieved by first sending the address location (64) to LCD command register. Next, the bitmap values (0, 4, 2, 31, 2, 4, 0, 0) are sent to the LCD data register. Now the arrow sign gets stored at the first address. Now whenever this symbol is to be displayed, its location needs to be sent to the command register of LCD.
To explain the above explanation in a better way. I am going to take an example. Lets make a “Bell” pattern as shown below.

Bytes values:-
Decimal
|
Binary
|
Hex-decimal
|
4
|
XXX00100
|
0X04
|
14
|
XXX01110
|
0X0E
|
14
|
XXX01110
|
0X0E
|
14
|
XXX01110
|
0X0E
|
31
|
XXX11111
|
0X1F
|
0
|
XXX00000
|
0X00
|
4
|
XXX00100
|
0X04
|
There’s a 64-byte hunk of RAM (random-access memory) that the LCD controller uses in the same way as character-generator (CG) ROM. When the controller receives an ASCII code in the range that’s mapped to the CG RAM, it uses the bit patterns stored there to display a pattern on the LCD. The concept here lies in the fact one can write to the CG RAM, thereby defining one’s own graphic symbols. Each byte of CG RAM is mapped to a five-bit horizontal row of pixels, and LCD characters are typically eight rows high, so 64 bytes of CG RAM is enough to define eight custom characters. These characters correspond to ASCII codes 0 through 7. When an LCD is first powered up, CG RAM contains random garbage bits. If necessary, CG RAM may be cleared by writing 00 into each CG RAM cell.
Writing to CG RAM
Writing to CG RAM is a lot like moving the cursor to a particular position on the display and displaying characters at that new location. The steps involved are:
· Set RS (Register Select) and R/W (Read/Write) pins of the LCD to initialize the LCD to accept instructions
· Set the CG RAM address by sending an instruction byte from 64 to 127 (locations 0-63 in CG RAM).
· Switch to Data Mode by changing the setting of RS pin
· Send bytes with the bit patterns for your symbol(s). The LCD controller automatically increments CG RAM addresses, in the same way as it increments cursor positions on the display.
· To leave CG RAM, switch to Command Mode to set address counter to a valid display address (e.g. 128, 1st character of 1st line); the clear-screen instruction (byte 1); or the home instruction (byte 2). Now bytes are once again being written to the visible portion of the display.
· To display the defined custom character print ASCII codes 0 through 7.
In the circuit, output of microcontroller AT89C51 (from port P2) goes to data pins of LCD numbered 7-14. The control pins RS (pin4), R/W (pin5) and EN (pin6) are connected to the pins 0, 1 and 6 of port P3 of the controller (P3^0, P3^1 & P3^6, respectively).
· We are not using row 8 as in our pattern it is not required. if you are using cursor then it is recommended not to use the 8th row. Now as we have got the values. We just need to put these values in the CGRAM. You can decided which place you want to store in.
Circuit Diagram

Project Datasheet
Filed Under: Electronic Projects
Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.
Tell Us What You Think!!
You must be logged in to post a comment.