0% found this document useful (0 votes)
7 views8 pages

Experiment

The document provides an overview of interfacing a 16x2 LCD display with the 8051 microcontroller, detailing the pin configuration, command structure, and programming methods. It explains the advantages of using LCDs over traditional CRTs, including their lower power consumption and versatility in displaying characters. The document also includes circuit diagrams and programming examples for sending data and commands to the LCD.

Uploaded by

Aziz Bohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
7 views8 pages

Experiment

The document provides an overview of interfacing a 16x2 LCD display with the 8051 microcontroller, detailing the pin configuration, command structure, and programming methods. It explains the advantages of using LCDs over traditional CRTs, including their lower power consumption and versatility in displaying characters. The document also includes circuit diagrams and programming examples for sending data and commands to the LCD.

Uploaded by

Aziz Bohra
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

‭EXPERIMENT 1‬

‭LCD Interfacing with 8051 – Working‬

‭LCD DISPLAY‬
‭16×2 LCD Pin Diagram‬

‭Pin Description‬

‭LCD COMMANDS‬

‭Interfacing LCD with Microcontroller –‬

‭CIRCUIT DIAGRAM‬

‭LCD DISPLAY‬
‭D‬

‭LCD‬
‭ e‬ ‭always‬ ‭use‬ ‭devices‬ ‭made‬ ‭up‬ ‭of‬ ‭Liquid‬
W
‭Crystal‬ ‭Displays‬ ‭(LCDs)‬ ‭like‬ ‭computers,‬

‭Interfacing‬ ‭digital‬ ‭watches,‬ ‭and‬ ‭also‬ ‭DVD‬ ‭and‬ ‭CD‬


‭players.‬ ‭They‬ ‭have‬ ‭become‬ ‭very‬ ‭common‬
‭and‬ ‭have‬ ‭taken‬ ‭a‬ ‭giant‬ ‭leap‬ ‭in‬ ‭the‬ ‭screen‬
‭industry‬ ‭by‬ ‭clearly‬ ‭replacing‬ ‭the‬ ‭use‬ ‭of‬
‭with 8051‬ ‭Cathode‬ ‭Ray‬ ‭Tubes‬ ‭(CRT).‬‭CRT‬‭draws‬‭more‬
‭power‬ ‭than‬ ‭LCD‬ ‭and‬ ‭is‬ ‭also‬ ‭bigger‬ ‭and‬
‭heavier.‬ ‭All‬ ‭of‬ ‭us‬‭have‬‭seen‬‭an‬‭LCD,‬‭but‬‭no‬

‭Microcontroller‬ ‭one‬ ‭knows‬ ‭the‬ ‭exact‬ ‭working‬ ‭of‬ ‭it.‬ ‭Let‬ ‭us‬
‭take a look at the working of an LCD.‬

‭ ere‬ ‭we‬ ‭are‬ ‭using‬ ‭alphanumeric‬‭LCD‬‭16×2‬‭.‬


H
‭A‬ ‭16×2‬ ‭LCD‬ ‭display‬ ‭is‬ ‭a‬ ‭very‬‭basic‬‭module‬
‭Table of Contents‬ ‭and‬ ‭is‬ ‭very‬ ‭commonly‬ ‭used‬ ‭in‬ ‭various‬
‭devices‬ ‭and‬ ‭circuits.‬ ‭These‬ ‭modules‬ ‭are‬
‭LCD DISPLAY‬ ‭preferred‬ ‭over‬ ‭seven‬ ‭segments‬ ‭and‬ ‭other‬
‭16×2 LCD Pin Diagram‬ ‭multi-segment LEDs.‬

‭Pin Description‬

‭LCD COMMANDS‬ ‭ he‬ ‭reasons‬ ‭are:‬ ‭LCDs‬ ‭are‬ ‭economical;‬


T
‭easily‬ ‭programmable;‬ ‭have‬‭no‬‭limitation‬‭of‬
‭Interfacing LCD with Microcontroller –‬
‭displaying‬ ‭special‬ ‭&‬ ‭even‬ ‭custom‬
‭CIRCUIT DIAGRAM‬ ‭characters‬ ‭(unlike‬ ‭in‬ ‭seven‬ ‭segments),‬
‭LCD Interfacing with 8051‬ ‭animations, and so on.‬

‭Microcontroller – Programming‬
‭Send Data‬ ‭ ‬ ‭16×2‬ ‭LCD‬ ‭means‬ ‭it‬ ‭can‬ ‭display‬ ‭16‬
A
‭characters‬ ‭per‬ ‭line‬ ‭and‬ ‭there‬ ‭are‬ ‭2‬ ‭such‬
‭Send String‬
‭lines.‬ ‭In‬ ‭this‬ ‭LCD‬ ‭each‬ ‭character‬ ‭is‬
‭Send Command‬
‭displayed‬‭in‬‭a‬‭5×7‬‭pixel‬‭matrix.‬‭This‬‭LCD‬‭has‬
‭LCD Initializing‬ ‭two‬‭registers,‬‭namely,‬‭Command‬‭and‬‭Data.‬
‭LCD Interfacing with 8051 – FULL‬ ‭The‬‭command‬‭register‬‭stores‬‭the‬‭command‬
‭CODE‬ ‭instructions‬ ‭given‬ ‭to‬ ‭the‬ ‭LCD.‬ ‭A‬ ‭command‬
‭is‬ ‭an‬ ‭instruction‬ ‭given‬ ‭to‬ ‭LCD‬ ‭to‬ ‭do‬ ‭a‬
‭ redefined‬ ‭task‬ ‭like‬ ‭initializing‬ ‭it,‬ ‭clearing‬
p
‭its‬ ‭screen,‬ ‭setting‬ ‭the‬ ‭cursor‬ ‭position,‬
‭controlling‬ ‭the‬ ‭display,‬ ‭etc.‬ ‭The‬ ‭data‬ ‭ ontrast adjustment;‬
C
‭3‬ ‭V‭E‬ E‬
‭register‬ ‭stores‬ ‭the‬ ‭data‬‭to‬‭be‬‭displayed‬‭on‬ ‭through a variable resistor‬
‭the‬‭LCD.‬‭The‬‭data‬‭is‬‭the‬‭ASCII‬‭value‬‭of‬‭the‬
‭character to be displayed on the LCD.‬

‭16×2 LCD Pin Diagram‬


‭Selects command register‬ ‭Regis‬
‭4‬ ‭when low; and data register‬ ‭ter‬
‭when high‬ ‭Select‬

‭Low to write to the register;‬


‭ ead‬
R
‭5‬ ‭High to read from the‬
‭/write‬
‭register‬

‭Pin Description‬

‭ ends data to data pins‬


S
‭Enabl‬
‭6‬ ‭when a high-to-low pulse is‬
‭e‬
‭ i‬
P ‭given‬
‭n‬ ‭Function‬ ‭Name‬
‭N‬
‭o‬

‭7‬ ‭DB0‬

‭Groun‬
‭1‬ ‭Ground (0V)‬
‭d‬

‭8‬ ‭DB1‬
‭8-bit data pins‬

‭Supply voltage; 5V (4.7V –‬


‭2‬ ‭Vcc‬
‭5.3V)‬
‭9‬ ‭DB2‬
‭ he‬ ‭LCD‬ ‭display‬ ‭module‬ ‭requires‬ ‭3‬ ‭control‬
T
‭lines‬‭as‬‭well‬‭as‬‭either‬‭4‬‭or‬‭8‬‭I/O‬‭lines‬‭for‬‭the‬
1‭ ‬ ‭data‬ ‭bus.‬ ‭The‬ ‭user‬ ‭may‬ ‭select‬‭whether‬‭the‬
‭DB3‬
‭0‬ ‭LCD‬ ‭is‬ ‭to‬ ‭operate‬ ‭with‬ ‭a‬ ‭4-bit‬‭data‬‭bus‬‭or‬
‭an‬ ‭8-bit‬ ‭data‬ ‭bus.‬ ‭If‬ ‭a‬ ‭4-bit‬ ‭data‬ ‭bus‬ ‭is‬
‭used‬ ‭the‬ ‭LCD‬ ‭will‬ ‭require‬ ‭a‬ ‭total‬ ‭of‬‭7‬‭data‬
‭lines‬ ‭(3‬ ‭control‬ ‭lines‬‭plus‬‭the‬‭4‬‭lines‬‭for‬‭the‬
‭data‬ ‭bus).‬ ‭If‬ ‭an‬ ‭8-bit‬ ‭data‬ ‭bus‬‭is‬‭used‬‭the‬
‭LCD‬ ‭will‬ ‭require‬ ‭a‬ ‭total‬ ‭of‬ ‭11‬ ‭data‬ ‭lines‬ ‭(3‬
1‭ ‬
‭DB4‬ ‭control‬ ‭lines‬ ‭plus‬ ‭the‬ ‭8‬ ‭lines‬ ‭for‬ ‭the‬ ‭data‬
‭1‬
‭bus).‬

‭ he‬‭three‬‭control‬‭lines‬‭are‬‭referred‬‭to‬‭as‬‭EN,‬
T
‭RS, and RW.‬

1‭ ‬
‭DB5‬
‭2‬ ‭ he‬ ‭EN‬ ‭line‬ ‭is‬ ‭called‬ ‭“Enable.”‬ ‭This‬ ‭control‬
T
‭line‬ ‭is‬ ‭used‬ ‭to‬ ‭tell‬ ‭the‬ ‭LCD‬ ‭that‬ ‭you‬ ‭are‬
‭sending‬ ‭it‬ ‭data.‬ ‭To‬ ‭send‬ ‭data‬ ‭to‬ ‭the‬ ‭LCD,‬
‭your‬ ‭program‬ ‭should‬ ‭make‬ ‭sure‬ ‭this‬‭line‬‭is‬
‭low‬ ‭(0)‬ ‭and‬ ‭then‬ ‭set‬ ‭the‬ ‭other‬ ‭two‬ ‭control‬
‭lines‬ ‭and/or‬ ‭put‬ ‭data‬ ‭on‬ ‭the‬ ‭data‬ ‭bus.‬
1‭ ‬
‭DB6‬ ‭When‬ ‭the‬ ‭other‬ ‭lines‬‭are‬‭completely‬‭ready,‬
‭3‬
‭bring‬‭EN‬‭high‬‭(1)‬‭and‬‭wait‬‭for‬‭the‬‭minimum‬
‭amount‬ ‭of‬ ‭time‬ ‭required‬ ‭by‬ ‭the‬ ‭LCD‬
‭datasheet‬ ‭(this‬ ‭varies‬ ‭from‬ ‭LCD‬ ‭to‬ ‭LCD),‬
‭and end by bringing it low (0) again.‬

‭1‬
‭DB7‬ ‭ he‬ ‭RS‬ ‭line‬ ‭is‬ ‭the‬ ‭“Register‬ ‭Select”‬ ‭line.‬
T
‭‬
4
‭When‬‭RS‬‭is‬‭low‬‭(0),‬‭the‬‭data‬‭is‬‭to‬‭be‬‭treated‬
‭as‬ ‭a‬ ‭command‬ ‭or‬ ‭special‬ ‭instruction‬‭(such‬
‭as‬ ‭a‬ ‭clear‬ ‭screen,‬ ‭position‬ ‭cursor,‬ ‭etc.).‬
‭When‬ ‭RS‬ ‭is‬ ‭high‬ ‭(1),‬‭the‬‭data‬‭being‬‭sent‬‭is‬
‭text‬‭data‬‭which‬‭should‬‭be‬‭displayed‬‭on‬‭the‬
1‭ ‬ ‭screen.‬‭For‬‭example,‬‭to‬‭display‬‭the‬‭letter‬‭“T”‬
‭Backlight V‬‭CC‬ ‭(5V)‬ ‭Led+‬
‭5‬ ‭on the screen you would set RS high.‬

‭ he‬‭RW‬‭line‬‭is‬‭the‬‭“Read/Write”‬‭control‬‭line.‬
T
‭When‬‭RW‬‭is‬‭low‬‭(0),‬‭the‬‭information‬‭on‬‭the‬
‭data‬‭bus‬‭is‬‭written‬‭to‬‭the‬‭LCD.‬‭When‬‭RW‬‭is‬
1‭ ‬ ‭high‬‭(1),‬‭the‬‭program‬‭is‬‭effectively‬‭querying‬
‭Backlight Ground (0V)‬ ‭Led-‬
‭6‬ ‭(or‬ ‭reading)‬ ‭the‬ ‭LCD.‬ ‭Only‬ ‭one‬ ‭instruction‬
‭(“Get‬ ‭LCD‬ ‭status”)‬ ‭is‬ ‭a‬ ‭read‬ ‭command.‬ ‭All‬
‭others‬ ‭are‬ ‭write‬ ‭commands–so‬ ‭RW‬ ‭will‬
‭almost always be LOW.‬
‭ inally,‬‭the‬‭data‬‭bus‬‭consists‬‭of‬‭4‬‭or‬‭8‬‭lines‬
F
‭(depending‬ ‭on‬ ‭the‬ ‭mode‬ ‭of‬ ‭operation‬
‭selected‬‭by‬‭the‬‭user).‬‭In‬‭the‬‭case‬‭of‬‭an‬‭8-bit‬
‭data‬ ‭bus,‬ ‭the‬ ‭lines‬ ‭are‬ ‭referred‬ ‭to‬ ‭as‬‭DB0,‬
‭DB1, DB2, DB3, DB4, DB5, DB6, and DB7.‬

‭LCD COMMANDS‬

‭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 to Port 2 (P2)‬

‭LCD‬ ‭Interfacing‬ ‭with‬


‭Now let’s move to the program.‬
‭8051‬ ‭Microcontroller‬
‭Interfacing‬ ‭LCD‬ ‭with‬ ‭– Programming‬
‭Microcontroller‬ ‭–‬
‭Send Data‬
‭CIRCUIT DIAGRAM‬
‭ o‬ ‭send‬ ‭data‬ ‭on‬ ‭the‬ ‭LCD,‬ ‭data‬ ‭is‬ ‭first‬
T
‭written‬ ‭to‬ ‭the‬ ‭data‬ ‭pins‬ ‭with‬ ‭R/W‬ ‭=‬ ‭0‬ ‭(to‬
‭specify‬ ‭the‬ ‭write‬ ‭operation)‬ ‭and‬‭RS‬‭=‬‭1‬‭(to‬
‭select‬‭the‬‭data‬‭register).‬‭A‬‭high‬‭to‬‭low‬‭pulse‬
‭is‬ ‭given‬ ‭at‬ ‭EN‬ ‭pin‬ ‭when‬ ‭data‬ ‭is‬‭sent.‬‭Each‬
‭write‬‭operation‬‭is‬‭performed‬‭on‬‭the‬‭positive‬
‭edge of the Enable signal.‬

‭void‬‭dat‬‭(‬‭unsigned‬‭char‬‭b)‬
‭{‬
‭Send Command‬

‭lcd_data=b;‬
‭ o‬ ‭send‬ ‭a‬ ‭command‬ ‭on‬ ‭the‬ ‭LCD,‬ ‭a‬
T
‭particular‬‭command‬‭is‬‭first‬‭specified‬‭to‬‭the‬
‭rs=1;‬ ‭data‬‭pins‬‭with‬‭R/W‬‭=‬‭0‬‭(to‬‭specify‬‭the‬‭write‬
‭operation)‬ ‭and‬ ‭RS‬ ‭=‬ ‭0‬ ‭(to‬ ‭select‬ ‭the‬
‭command‬ ‭register).‬ ‭A‬ ‭high‬ ‭to‬ ‭low‬ ‭pulse‬ ‭is‬
‭r w=0;‬ ‭given at the EN pin when data is sent.‬

‭en=1;‬ ‭void‬‭cmd‬‭(‭u
‬ nsigned‬‭char‬‭a)‬

‭lcd_delay‬‭();‬ ‭{‬

‭en=0;‬ ‭lcd_data=a;‬

‭}‬ ‭rs=0;‬

‭r w=0;‬
‭Send String‬

‭en=1;‬
‭ e‬ ‭cannot‬ ‭send‬ ‭more‬ ‭than‬ ‭8‬ ‭bits‬ ‭at‬ ‭the‬
W
‭same‬ ‭time.‬ ‭Because‬ ‭data‬ ‭lines‬ ‭are‬ ‭only‬
‭having‬ ‭8‬ ‭bits.‬ ‭So‬ ‭how‬ ‭we‬ ‭can‬ ‭send‬‭string?‬ ‭lcd_delay‬‭();‬
‭Any‬ ‭guess?‬‭Yeah,‬‭you‬‭are‬‭correct.‬‭We‬‭have‬
‭to‬ ‭send‬ ‭the‬ ‭string‬ ‭by‬ ‭character.‬ ‭See‬ ‭this‬
‭code.‬ ‭en=0;‬

‭void‬‭show‬‭(‭u
‬ nsigned‬‭char‬‭*s)‬ ‭}‬

‭{‬
‭LCD Initializing‬

‭while‬‭(*s) {‬
‭ o‬ ‭initialize‬‭the‬‭LCD‬‭we‬‭have‬‭to‬‭use‬‭certain‬
T
‭commands.‬
‭dat‬‭(*s++);‬

‭void‬‭lcd_init‬‭()‬

‭}‬

‭{‬

‭}‬

‭cmd‬‭(‬‭0x38‬‭);‬
‭cmd‬‭(‭0
‬ x0e‬‭);‬ ‭void‬‭lcd_delay‬‭();‬

‭cmd‬‭(‭0
‬ x01‬‭);‬ ‭void‬‭lcd_init‬‭()‬

‭cmd‬‭(‭0
‬ x06‬‭);‬ ‭{‬

‭cmd‬‭(‭0
‬ x0c‬‭);‬ ‭cmd‬‭(‬‭0x38‬‭);‬

‭cmd‬‭(‭0
‬ x80‬‭);‬ ‭cmd‬‭(‬‭0x0e‬‭);‬

‭}‬ ‭cmd‬‭(‬‭0x01‬‭);‬

‭Now see the full code below.‬ ‭cmd‬‭(‬‭0x06‬‭);‬

‭LCD‬ ‭Interfacing‬ ‭with‬ ‭cmd‬‭(‬‭0x0c‬‭);‬

‭8051 – FULL CODE‬ ‭cmd‬‭(‬‭0x80‬‭);‬

‭}‬

‭#include <reg51.h>‬

‭void‬‭cmd‬‭(‭u
‬ nsigned‬‭char‬‭a)‬

‭#define lcd_data P2‬

‭{‬

‭sbit rs=P0^0;‬

‭lcd_data=a;‬

‭sbit rw=P0^1;‬

‭rs=0;‬

‭sbit en=P0^2;‬

‭r w=0;‬

‭void‬‭lcd_init‬‭();‬

‭en=1;‬

‭void‬‭cmd‬‭(‭u
‬ nsigned‬‭char‬‭a);‬

‭lcd_delay‬‭();‬

‭void‬‭dat‬‭(‭u
‬ nsigned‬‭char‬‭b);‬

‭en=0;‬

‭void‬‭show‬‭(‭u
‬ nsigned‬‭char‬‭*s);‬
‭}‬ ‭unsigned‬‭int‬‭lcd_delay;‬

‭void‬‭dat‬‭(‭u
‬ nsigned‬‭char‬‭b)‬ ‭for‬‭(lcd_delay=0;lcd_delay<=6000;lcd_delay++);‬

‭{‬ ‭}‬

‭lcd_data=b;‬ ‭int‬‭main‬‭()‬

‭rs=1;‬ ‭{‬

‭r w=0;‬ ‭unsigned‬‭int‬‭j;‬

‭en=1;‬ ‭lcd_init‬‭();‬

‭lcd_delay‬‭();‬ ‭while‬‭(1) {‬

‭en=0;‬ ‭cmd‬‭(‬‭0x80‬‭);‬

‭}‬ ‭show‬‭(‬‭" Welcome To "‬‭);‬

‭void‬‭show‬‭(‭u
‬ nsigned‬‭char‬‭*s)‬ ‭cmd‬‭(‬‭0xc0‬‭);‬

‭{‬ ‭show‬‭(‬‭" EMBETRONICX.COM"‬‭);‬

‭while‬‭(*s) {‬ ‭for‬‭( j=0; j<30000; j++);‬

‭dat‬‭(*s++);‬ ‭cmd‬‭(‬‭0x01‬‭);‬

‭}‬ ‭for‬‭( j=0; j<30000; j++);‬

‭}‬ ‭}‬

‭void‬‭lcd_delay‬‭()‬ ‭}‬

‭{‬
‭LCD Interfacing with‬
‭8051 – Working‬

You might also like