Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering

How to create custom characters on 16×2 LCD using 8051 microcontroller (AT89C51)- (Part 10/45)

By Himanshu Choudhary

The commonly used 16x2 LCD can also display custom made characters besides numbers, alphabets & special characters. Any character can be made to appear on a 5x8 pixel matrix element without knowledge of its ASCII value. The idea explained here demonstrates the principle and operation of a simple LCD custom character display using 8051 microcontroller (AT89C51).

 


 

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 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
1
72
2
80
3
88
4
96
5
104
6
112
7
120
 Fig. 2: Symbol locations with base addresses in ROM
 
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.
 
Bitmap Layout And Values of LCD
Fig. 3: Bitmap Layout And Values of LCD
 
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).
 
 

 

Project Source Code

###

//Program to create and display custom characters  smilies, heart, musical note symbol

#include<reg51.h>
sfr lcd_data_pin=0xA0; 
sbit rs=P3^0;  //Register select pin
sbit rw=P3^1;  // Read write pin
sbit en=P3^6;  //Enable pin

void delay(unsigned int count)  // Function to provide time delay in msec.
{
int i,j;
for(i=0;i<count;i++)
  for(j=0;j<1275;j++);
}

void lcd_command(unsigned char comm)  //Function to send commands to LCD.
{
lcd_data_pin=comm;
en=1; 
rs=0; 
rw=0; 
delay(1);
en=0;
}

void lcd_data(unsigned char disp)  //Function to send data to LCD
{
lcd_data_pin=disp;
en=1; 
rs=1; 
rw=0; 
delay(1);
en=0;
}

void lcd_ini()  //Function to initialize the LCD
{
lcd_command(0x38);  
delay(2);
lcd_command(0x0F); 
delay(2);
lcd_command(0x82);  //Set cursor to blink at line 1 positon 2
delay(2);
}

void character()
{
lcd_command(64);  //Address where values of the first custom character is stored
lcd_data(0);
lcd_data(10);
lcd_data(21);
lcd_data(17);
lcd_data(10);
lcd_data(4);
lcd_data(0);
lcd_data(0);
lcd_command(0xC0);  //Address of the location where the character is to be displayed
lcd_data(0);  // Displaying the character created at address 0x64 
delay(10);

lcd_command(72);
lcd_data(0);
lcd_data(0);
lcd_data(0);
lcd_data(10);
lcd_data(0);
lcd_data(4);
lcd_data(17);
lcd_data(14);
lcd_command(0x80);
lcd_data(1);
delay(10);

lcd_command(80);
lcd_data(0);
lcd_data(0);
lcd_data(10);
lcd_data(0);
lcd_data(4);
lcd_data(0);
lcd_data(14);
lcd_data(17);
lcd_command(0x82);
lcd_data(2);
delay(10);
lcd_command(88);
lcd_data(1);
lcd_data(3);
lcd_data(5);
lcd_data(9);
lcd_data(9);
lcd_data(11);
lcd_data(27);
lcd_data(24);
lcd_command(0x84);
lcd_data(3);
delay(10);

lcd_command(96);
lcd_data(0);
lcd_data(10);
lcd_data(0);
lcd_data(31);
lcd_data(17);
lcd_data(14);
lcd_data(0);
lcd_data(0);
lcd_command(0x86);
lcd_data(4);
delay(10);

lcd_command(104);
lcd_data(10);
lcd_data(0);
lcd_data(4);
lcd_data(0);
lcd_data(14);
lcd_data(17);
lcd_data(17);
lcd_data(14);
lcd_command(0xC2);
lcd_data(5);
delay(10);

lcd_command(112);
lcd_data(0);
lcd_data(10);
lcd_data(0);
lcd_data(0);
lcd_data(4);
lcd_data(0);
lcd_data(31);
lcd_data(0);
lcd_command(0xC4);
lcd_data(6);
delay(10);

lcd_command(120);
lcd_data(0);
lcd_data(17);
lcd_data(10);
lcd_data(17);
lcd_data(4);
lcd_data(0);
lcd_data(14);
lcd_data(17);
lcd_command(0xC6);
lcd_data(7);
delay(10);
}

void main()
{
lcd_ini();
character();
}

###

 


Circuit Diagrams

Circuit-Diagram-Creating-Custom-Characters-16×2-LCD-8051-Microcontroller-AT89C51

Project Components

  • AT89C51 Microcontroller
  • LCD
  • Preset

Project Video


Filed Under: 8051 Microcontroller
Tagged With: 8051, character, display, lcd, microcontroller
 

Questions related to this article?
👉Ask and discuss on Electro-Tech-Online.com and EDAboard.com forums.



Tell Us What You Think!! Cancel reply

You must be logged in to post a comment.

HAVE A QUESTION?

Have a technical question about an article or other engineering questions? Check out our engineering forums EDABoard.com and Electro-Tech-Online.com where you can get those questions asked and answered by your peers!


Featured Tutorials

  • Introduction to Brain Waves & its Types (Part 1/13)
  • Understanding NeuroSky EEG Chip in Detail (Part 2/13)
  • Performing Experiments with Brainwaves (Part 3/13)
  • Amplification of EEG Signal and Interfacing with Arduino (Part 4/13)
  • Controlling Led brightness using Meditation and attention level (Part 5/13)
  • Control Motor’s Speed using Meditation and Attention Level of Brain (Part 6/13)

Stay Up To Date

Newsletter Signup

Sign up and receive our weekly newsletter for latest Tech articles, Electronics Projects, Tutorial series and other insightful tech content.

EE Training Center Classrooms

EE Classrooms

Recent Articles

  • What are the battery-selection criteria for low-power design?
  • Key factors to optimize power consumption in an embedded device
  • EdgeLock A5000 Secure Authenticator
  • How to interface a DS18B20 temperature sensor with MicroPython’s Onewire driver
  • Introduction to Brain Waves & its Types (Part 1/13)

Most Popular

5G 555 timer circuit 8051 ai Arduino atmega16 automotive avr bluetooth dc motor display Electronic Part Electronic Parts Fujitsu ic infineontechnologies integratedcircuit Intel IoT ir lcd led maximintegratedproducts microchip microchiptechnology Microchip Technology microcontroller microcontrollers mosfet motor powermanagement Raspberry Pi remote renesaselectronics renesaselectronicscorporation Research samsung semiconductor sensor software STMicroelectronics switch Technology vishayintertechnology wireless

RSS EDABOARD.com Discussions

  • Avalanche Pulser
  • Measure AC current accurateley (100mA to 10A)
  • SDR with external LO input
  • Timer MC14541B wrong delay
  • simple LSB explanation please

RSS Electro-Tech-Online.com Discussions

  • bluetooth jammer
  • Disabled son needs advice please
  • DIY bluetooth speaker
  • Someone please explain how this BMS board is supposed to work?
  • HV Diodes
Engineers Garage
  • Analog IC TIps
  • Connector Tips
  • DesignFast
  • EDABoard Forums
  • EE World Online
  • Electro-Tech-Online Forums
  • Microcontroller Tips
  • Power Electronic Tips
  • Sensor Tips
  • Test and Measurement Tips
  • 5G Technology World
  • About Us
  • Contact Us
  • Advertise

Copyright © 2022 WTWH Media LLC. All Rights Reserved. The material on this site may not be reproduced, distributed, transmitted, cached or otherwise used, except with the prior written permission of WTWH Media
Privacy Policy | Advertising | About Us

Search Engineers Garage

  • Projects and Tutorials
    • Electronic Projects
      • 8051
      • Arduino
      • ARM
      • AVR
      • PIC
      • Raspberry pi
      • STM32
    • Tutorials
    • Circuit Design
    • Project Videos
    • Components
  • Articles
    • Tech Articles
    • Insight
    • Invention Stories
    • How to
    • What Is
  • News
    • Electronic Products News
    • DIY Reviews
    • Guest Post
  • Forums
    • EDABoard.com
    • Electro-Tech-Online
    • EG Forum Archive
  • Digi-Key Store
    • Cables, Wires
    • Connectors, Interconnect
    • Discrete
    • Electromechanical
    • Embedded Computers
    • Enclosures, Hardware, Office
    • Integrated Circuits (ICs)
    • Isolators
    • LED/Optoelectronics
    • Passive
    • Power, Circuit Protection
    • Programmers
    • RF, Wireless
    • Semiconductors
    • Sensors, Transducers
    • Test Products
    • Tools
  • EE Resources
    • DesignFast
    • LEAP Awards
    • Oscilloscope Product Finder
    • White Papers
    • Webinars
  • EE Learning Center
    • Design Guides
      • WiFi & the IOT Design Guide
      • Microcontrollers Design Guide
      • State of the Art Inductors Design Guide
  • Women in Engineering