How to Display Text on 16×2 Character Lcd




Displaying Text on 16×1, 16×2 or any size of character lcd is not a complex task. Once you know about the internal structure of the character lcd, lcd pin out, registers associated with lcd’s and CG-RAM(Character Generated RAM) then its all on your finger tips. If you are really interested in lcd programming, and want to know about how to display text on lcd? First take a small tutorial on the Internal Structure of character 16×2 Lcd. Because if you don’t know about internal structure of lcd you will be unable to fully understand the sequence of steps taken to display text on Lcd given below. 

Character lcd can perform both read and write functions. Normally lcds are only used to write text on them. Read operation is performed in few nominal tasks. Below are some steps to display text on lcd. I am going to display Character ‘A’ on lcd.

Displaying Text on 16×2 lcd using microcontroller step by step

  1. First select the operation which you want to perform ‘Read’ or ‘Write’. Making R/W Pin of Lcd 0(R/W=0) will select the write operation. Now lcd is set in write mode and you can write any text to lcd. If R/W=1 lcd is set in Read mode and you can read data from lcd. Since i want to display ‘A‘ on lcd. I made R/W=0.

Displaying Text on 16×2 lcd using microcontroller step by step

2. Their are two registers in lcd data and command. To display text on lcd you have to select data register of lcd. To execute command you have to select command register of lcd. To select data register make RS=1. To switch to command register make Rs=0. In our case we are displaying text on lcd so make RS=1.

Character Lcd RS(Register Select Pin)

3. Place your text on data pins of Lcd. Since lcd’s data pins are 8-bit wide so place data that is 8-bit wide. Since we want to display ‘A‘ on lcd. ASCII value of ‘A‘ is 65(decimal), 01000001(Binary), 0x41 (Hexadecimal). Place this value on lcd data pins. 

Character Lcd data pins. Data Placed on Data Pins

4. Now make en=1 and after some microseconds again make en=0. This en signal gives a push to data placed in data register or on data pins to display on 16×2 screen.

Text Displayed on Character lcd

To display next character repeat the above steps again.To make lcd fully functional you first have to initialize lcd. By initialization i mean set the font of character, decide the cursor(Blinking or not blinking) select the position where you want to display character etc. These parameters are set by sending commands to lcd. Standard lcd commands and their functions are given in the link below.


Note: To execute commands steps are same like to display text only difference is in the RS pin selection. To execute commands you have to select the command register of lcd. Make RS=0 to select command register of lcd. Now your commands goes to command register and you can execute them by make en=1 and back to en=0.

Simple text display on 16×2 lcd demo project using 8051 microcontroller

In this project i will display my name “USMAN ALI BUTT” on both rows of 16×2 lcd. First my name will appear on first row of 16×2 lcd. Then after some time it disappears and re appears on second line of 16×2 lcd. The project is really simple.
Hardware requirements

  • 16×2 character lcd.
  • 89c51 or 89c52 microcontroller.
  • Bread board large enough to make circuit on it
  • 5 volts DC power supply.
  • Potentiometer for setting lcd contrast.
  • Software for codding, keil etc
  • Burner to burn code in the microcontroller

Dispay text on 16×2 lcd – Project code

The circuit for the project is simple. Connect Port-1 of your 8051(89c51,89c52) microcontroller to 8 data pins of the lcd. The pins should interface the microcontroller in the order that pin#1 of Port-1 is connected to pin#1 of data pin on lcd. Pin#2 of Port-1 of 8051 to pin#2 of lcd and so on up till pin 8. Connect pin#5 of Port-3 to rs(register select) pin of lcd. pin#7 of microcontroller Port-3 to rw(read write) pin of lcd and pin#6 of microcontroller Port-3 to en(enable) pin of lcd. ​

Rest of the connections are same as we made in all of our circuits apply 5 volts to vcc pin#40 and Pin#31 of 8051(89c51,89c52). Ground pin#20. Attach crystal of 11.0592MHz frequency in parallel to two 33pf capacitors to pin#18(XTAL1) and Pin#19(XTAL2) of microcontroller. You can also use crystal of any other frequency if you want and capacitors with them can very from 27pf to 33pf.
 
Displaying Text on Character Lcd with 8051(89c51,89c52) microcontroller
 
#include<reg51.h>
 sbit rs=P3^5; //Register select (RS)
 sbit rw=P3^7; //Read write (RW) pin
 sbit en=P3^6; //Enable (EN) pin
 void delay(unsigned int time) //Time delay function
 {
 unsigned int i,j;
 for(i=;i< time;i++)
 for(j=;j<5;j++);
 }
 //Function for sending Commands to the command register of LCD
 void lcdcmd(unsigned char value)
 {
 P1=value;
 //P3=0x40;
 rw=;
 rs=;
 en=1;
 delay(50);
 en=;
 delay(50);
 return;
 }
 //Function for sending data to the data register of LCD
 void display(unsigned char value)
 {
 P1=value;
 //P3=0x60;
 rw=;
 rs=1;
 en=1;
 delay(500);
 en=;
 delay(50);
 return;
 }
 //Function to initialize the registers and pins of LCD
 //always use with every lcd of hitachi
 void lcdint(void) //Function sending commands to lcd. To initialize lcd
 {
 P1=0x00;
 P3=0x00;
 delay(15000);display(0x30);delay(4500);display(0x30);delay(300);
 display(0x30);delay(650);lcdcmd(0x38);delay(50);lcdcmd(0x0F);
 delay(50);lcdcmd(0x01);delay(50);lcdcmd(0x06);delay(50);lcdcmd(0x80);
 delay(50);
 }
 //MAIN FUNCTION
 void main()
 {
 int i,j,k=,l=,s=;
 char u[]={USMAN ALI BUTT};
 char sec[]={JUMPING TO SECOND LINE};
 lcdint(); //Initialize Lcd
 lcdcmd(0x01); //Clear Lcd Command
 lcdcmd(0x80);
 while(u[k]!=\0)
 {
 display(u[k]);
 k++;
 }
 delay(100000);
 lcdcmd(0x01); //Clear all contents of lcd
 lcdcmd(0x80); //Initialize Cursor to first character matrix of lcd
 while(sec[s]!=\0)
 {
 if(s==15)
 lcdcmd(0xC0); //Initializing Cursor to second line first Character matrix
 display(sec[s]);
 s++;
 }
 delay(100000);
 lcdcmd(0x01);
 lcdcmd(0xC0); //Initializing Cursor to second line first Character matrix
 while(u[l]!=\0)
 {
 display(u[l]); //Printing same string on second line
 l++;
 }
 delay(100000);
 }
 
More Projects related to displaying Text On 16×2 lcd are given below. Each project is made using different type of microcontroller, arduino pic microcontroller etc. Projects are open source. You can use and edit code according to your need.
 

To learn difference between sending commands and data to lcd click. Difference between sending commands and data to lcd. If you feel any difficulties in code just leave a comment regarding your problem. I will definitely figure it out.







Source: How to Display Text on 16×2 Character Lcd




Leave a Comment

*
= 5 + 5

Read previous post:
PCBA SERVICE REVIEW – COMPARING PCBWAY VS LOCOPCB VS PCBGOGO VS SEEEDSTUDIO
PCBA SERVICE REVIEW – COMPARING PCBWAY VS LOCOPCB VS PCBGOGO VS SEEEDSTUDIO

Daniel Eichhorn @ blog.squix.org, shares his experience with some popular PCBA services and documents his finding on his blog. He...

Close
Scroll to top