Hi guys…. In our last tutorial we have seen How to interface LCD to 8051. In this tutorial we are going to see how to generate LCD Custom Character using 8051.
How to generate LCD Custom Character using 8051
Introduction
So we know how to display alphanumeric characters in LCD. We can easily display that. Because it is already stored in the ROM memory of LCD. Before that we should know the memories of LCD. There are three types of memory present in the LCD display.
- CG ROM
- DD RAM
- CG RAM
CG ROM (Character Generator ROM)
This memory holds the pattern for every single character of predefined LCD font. and you call the content of this memory by the placing corresponding ASCII value on the LCD port . For example if you want to display ‘A’ you have to send the ASCII value of ‘A’ which is 0x41 to the LCD. So we cannot modify its contents which is stored already.
DD RAM (Display Data RAM)
DDRAM is the memory which holds only those characters which are currently on the screen . means if there is a message is currently being displayed on the screen then it has to be on the DDRAM. For example if you want to display “hello” on the screen then you have to load pattern of h from the CG ROM to DD RAM then do the same for ‘e’ ,’l’ ,’l’ and ‘o’.
This is the address of the DDRAM memory in 16×2 LCD
Position | 1 | 2 | 3 | 4 | ..... | 16 |
---|---|---|---|---|---|---|
Row1 | 0x80 | 0X81 | 0X82 | 0X83 | ...... | 0X8F |
Row2 | 0xC0 | 0XC1 | 0XC2 | 0XC3 | ...... | 0XCF |
This memory works same as CG ROM but as this is RAM we can modify it’s content any time. So this is the place where we can store our custom character pattern. Then that pattern can be sent to display.
CG RAM (Character generator RAM)
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 adress starting from 0x40. Bit 7 is 0 and Bit 6 is 1, due to which the CGRAM adress 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.
This code will print the custom character in Tamil language. Tamil language is not in the LCD. So that i’m going to create the few characters from the Tamil language. You can also try in your language. See the code attached below.
Pin Diagram
RS is connected to Port 0.0 (P0.0)
RW is connected to Port 0.1 (P0.1)
EN is connected to Port 0.2 (P0.2)
Data lines are connected into Port 2 (P2)
CODE
#include <reg51.h> #define lcd_data P2 sbit rs=P0^0; sbit rw=P0^1; sbit en=P0^2; void lcd_init(); void cmd(unsigned char a); void dat(unsigned char b); void show(unsigned char *s); void lcd_delay(); void lcd_init() { cmd(0x38); cmd(0x0e); cmd(0x01); cmd(0x06); cmd(0x0c); cmd(0x80); } void cmd(unsigned char a) { lcd_data=a; rs=0; rw=0; en=1; lcd_delay(); en=0; } void dat(unsigned char b) { lcd_data=b; rs=1; rw=0; en=1; lcd_delay(); en=0; } void show(unsigned char *s) { while(*s) { dat(*s++); } } void lcd_delay() { unsigned int lcd_delay; for(lcd_delay=0;lcd_delay<=6000;lcd_delay++); } void store() { cmd(64); //First location dat(31); dat(20); dat(31); dat(21); dat(29); dat(1); dat(15); dat(0); cmd(72); //Second location dat(1); dat(2); dat(2); dat(23); dat(21); dat(21); dat(31); dat(0); cmd(80); //Third location dat(4); dat(0); dat(23); dat(21); dat(31); dat(4); dat(28); dat(0); } void main() { lcd_init(); store(); //Storing the custom characters while(1) { cmd(0x1c); //Scroll command cmd(0x85); //Location dat(0); dat(1); dat(2); } }
OUTPUT
[ Image : Output ]
In our next tutorial, we will see how to interface LCD in 4-bit mode.
You can also read the below tutorials.

Embedded Software | Firmware | Linux Devic Deriver | RTOS
Hi, I’m SLR. I am a tech blogger and an Embedded Engineer. I am always eager to learn and explore tech-related concepts. And also, I wanted to share my knowledge with everyone in a more straightforward way with easy practical examples. I strongly believe that learning by doing is more powerful than just learning by reading. I love to do experiments. If you want to help or support me on my journey, consider sharing my articles, or Buy me a Coffee! Thank you for reading my blog! Happy learning!