Micro c lab6(lcd)
Transcript of Micro c lab6(lcd)
MicrocontrollersLab 6
INTERFACING LCD DISPLAY USING 8051
Objectives of the LabLearning 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 withcaution
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 LabSETB Px.yCLR Px.yNOPSee 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 busy1. RS=02. R/=13. E=0 => E=14. 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 subroutineLCD 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/=04. E=1 => E=05. 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/DataLabel
Clear/Set RS
Call Delay
setb ennopclr 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,#line1again:mov a,#0movc a,@a+dptrinc dptrjz exit1; jump if accumulator is zerocall data_wrt; subroutine to display single characterjmp againexit1:
line1: db “Hello World”,0
Semi-final Pseudo-Code What we have to do to display overall data on LCD is
following1. Define pin and port names2. 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 Subroutine6. 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 Lab1. AT89c51
2. 16x2 LCD
Lab TasksDisplay Workstation#XY on line1 and ID numbers on line
2.
Quiz Next Week of Keypad and Stepper Motor.
Individual Project Briefing during Experiment.