INTERFACING LCD DISPLAY USING 8051
Objectives of the Lab
 Learning pin configurations of 8051
 Learning important commands for LCD
 Learning subroutines for displaying command and data
 Displaying specific data on LCD.
Deciding Pins or Ports to use
Use with
caution
If EA high
*As LCD needs
11 pins, we will
use P2 and P3.
LCD
 Keypads are usually used
for displaying messages.
 There are 2 lines and
each line can display 16
characters. That’s why it
is called 16x2 line
display.
 It is widely used in
applications that use
MENU or display values.
 It is a good alternative
for SSDs.
Pin Configuration
Important Commands
1.
2. on
3.
4.
Instructions used in this Lab
 SETB Px.y
 CLR Px.y
 NOP
 See instruction set for the details of above commands.
LCD Timing for Read
LCD Read Subroutine (BF check)
 LCD read is only needed to check busy flag, to check if LCD is
busy. Busy flag is D7. If it is set, the LCD is busy
1. RS=0
2. R/ 𝑊=1
3. E=0 => E=1
4. Stay here if bf=1.
There is a passive way to send command or data without
checking the BF of LCD. If delay greater than 200 nanoseconds
is between the commands or data for LCD, there is no need for
BF.
LCD Timing for Write
LCD Write subroutine
 LCD write is used for writing command and/or data to
LCD.
1. Move data in A to port where Data pins of LCD are
connected.
2. RS=0 for command, RS=1 for data.
3. R/ 𝑊=0
4. E=1 => E=0
5. Check BF or give delay.
Pin naming and data display
 Instead of calling pins by their ports, we can also give custom
names to pins and use it during code e.g.
rs bit p3.5 => setb rs; this means setb p3.5
rw bit p3.6 and en bit p3.7.
 This is done below ‘org 00h’ and above the rest of the code.
For port, mydata equ P2 (pin 2.0 to D0 and so on…)
 To display character use mov a,#‘X’.
 To display integer, first make it ASCII, add a,30h.
 To display a line, use look-up table.
line1: db “HELLO WORLD”,0
 Soon, we will see the need to append 0 at the end of line.
Subroutine for Writing
Command/Data
Label
Clear/Set
RS
Call Delay
setb en
nop
clr en
Move
command/
data to P2
H to L
pulse to
enable
ret
Using Lookup Table for display
 The display of character array is simple, the difficult task is to end
that display. For this, we keep a zero at the end of the line and check
if the data is zero.
mov dptr,#line1
again:
mov a,#0
movc a,@a+dptr
inc dptr
jz exit1; jump if accumulator is zero
call data_wrt; subroutine to display single character
jmp again
exit1:
line1: db “Hello World”,0
Semi-final Pseudo-Code
 What we have to do to display overall data on LCD is
following
1. Define pin and port names
2. Initialize LCD by sending (38h,0Eh,01h followed by
command write subroutine)
3. Then data of line1 using lookup table (use data write
subroutine)
4. Then data of line2 using lookup table (use data write
subroutine)
5. Command Write Subroutine and Data Write Subroutine
6. Delay Subroutine
Final Pseudo-Code
 The above Pseudo code works during software test but during
hardware we need to add some more steps before step 2.
 We need to send 030h, commands 3 times with a delay of 50
milli-seconds to initialize the hardware LCD which during
software is not needed.
Proteus Devices needed in this Lab
1. AT89c51
2. 16x2 LCD
Lab Tasks
 Display Workstation#XY on line1 and ID numbers on line
2.
 Quiz Next Week of Keypad and Stepper Motor.
 Individual Project Briefing during Experiment.

Micro c lab6(lcd)

  • 1.
  • 2.
    Objectives of theLab  Learning pin configurations of 8051  Learning important commands for LCD  Learning subroutines for displaying command and data  Displaying specific data on LCD.
  • 3.
    Deciding Pins orPorts to use Use with caution If EA high *As LCD needs 11 pins, we will use P2 and P3.
  • 4.
    LCD  Keypads areusually used for displaying messages.  There are 2 lines and each line can display 16 characters. That’s why it is called 16x2 line display.  It is widely used in applications that use MENU or display values.  It is a good alternative for SSDs.
  • 5.
  • 6.
  • 7.
    Instructions used inthis Lab  SETB Px.y  CLR Px.y  NOP  See instruction set for the details of above commands.
  • 8.
  • 9.
    LCD Read Subroutine(BF check)  LCD read is only needed to check busy flag, to check if LCD is busy. Busy flag is D7. If it is set, the LCD is busy 1. RS=0 2. R/ 𝑊=1 3. E=0 => E=1 4. Stay here if bf=1. There is a passive way to send command or data without checking the BF of LCD. If delay greater than 200 nanoseconds is between the commands or data for LCD, there is no need for BF.
  • 10.
  • 11.
    LCD Write subroutine LCD write is used for writing command and/or data to LCD. 1. Move data in A to port where Data pins of LCD are connected. 2. RS=0 for command, RS=1 for data. 3. R/ 𝑊=0 4. E=1 => E=0 5. Check BF or give delay.
  • 12.
    Pin naming anddata display  Instead of calling pins by their ports, we can also give custom names to pins and use it during code e.g. rs bit p3.5 => setb rs; this means setb p3.5 rw bit p3.6 and en bit p3.7.  This is done below ‘org 00h’ and above the rest of the code. For port, mydata equ P2 (pin 2.0 to D0 and so on…)  To display character use mov a,#‘X’.  To display integer, first make it ASCII, add a,30h.  To display a line, use look-up table. line1: db “HELLO WORLD”,0  Soon, we will see the need to append 0 at the end of line.
  • 13.
    Subroutine for Writing Command/Data Label Clear/Set RS CallDelay setb en nop clr en Move command/ data to P2 H to L pulse to enable ret
  • 14.
    Using Lookup Tablefor display  The display of character array is simple, the difficult task is to end that display. For this, we keep a zero at the end of the line and check if the data is zero. mov dptr,#line1 again: mov a,#0 movc a,@a+dptr inc dptr jz exit1; jump if accumulator is zero call data_wrt; subroutine to display single character jmp again exit1: line1: db “Hello World”,0
  • 15.
    Semi-final Pseudo-Code  Whatwe have to do to display overall data on LCD is following 1. Define pin and port names 2. Initialize LCD by sending (38h,0Eh,01h followed by command write subroutine) 3. Then data of line1 using lookup table (use data write subroutine) 4. Then data of line2 using lookup table (use data write subroutine) 5. Command Write Subroutine and Data Write Subroutine 6. Delay Subroutine
  • 16.
    Final Pseudo-Code  Theabove Pseudo code works during software test but during hardware we need to add some more steps before step 2.  We need to send 030h, commands 3 times with a delay of 50 milli-seconds to initialize the hardware LCD which during software is not needed.
  • 17.
    Proteus Devices neededin this Lab 1. AT89c51 2. 16x2 LCD
  • 18.
    Lab Tasks  DisplayWorkstation#XY on line1 and ID numbers on line 2.  Quiz Next Week of Keypad and Stepper Motor.  Individual Project Briefing during Experiment.