0% found this document useful (0 votes)
30 views27 pages

MPMC - 5.1 8051 InputOutput Interfacing - LCD and LED

Uploaded by

srinidi.kn2022
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)
30 views27 pages

MPMC - 5.1 8051 InputOutput Interfacing - LCD and LED

Uploaded by

srinidi.kn2022
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/ 27

5.

1 8051 Input/Output interfacing – LCD and LED

5.1 8051 Input/Output interfacing –


LCD and LED
Note: LED is already discussed (on/off a port bit)
Module:5 I/O interfacing with Microcontroller 8051
Course: BECE204L – Microprocessors and Microcontrollers
-Dr Richards Joe Stanislaus
Associate Professor - SENSE
Email: [email protected]
5.1 8051 Input/Output interfacing – LCD and LED

Module:5 I/O interfacing with


Microcontroller 8051

• LCD, LED, Keypad, Analog-to-Digital Convertors, Digital-to-Analog


Convertors, Sensor with Signal Conditioning Interface

Mohammad Ali Mazidi, Janice G. Mazidi, Rolin D. McKinlay, The 8051 Microcontroller and
Embedded Systems, 2014, 2nd Edition, Pearson, India.
5.1 8051 Input/Output interfacing – LCD and LED

1. Why an LCD is needed?


 Display units are the most important output devices in embedded
projects and electronics products.
 LCD is finding widespread use replacing LEDs
 The declining prices of LCD
 The ability to display numbers, characters and graphics
 Incorporation of a refreshing controller into the LCD, thereby
relieving the CPU of the task of refreshing LCD
 Ease of programming for characters and graphics
5.1 8051 Input/Output interfacing – LCD and LED

2. 16x2 LCD : Most commonly used display unit


 16x2 LCD is one of the most used display unit.
 As per the name the 2x16 has 2 lines with 16 characters on each
line.
 It supports all the ASCII chars and is basically used for
displaying the alpha numeric characters.
 Here each character is displayed in a matrix of 5x7 pixels.
 Apart from alpha numeric chars it also provides the provision to
display the custom characters by creating the pattern.
5.1 8051 Input/Output interfacing – LCD and LED
5.1 8051 Input/Output interfacing – LCD and LED
5.1 8051 Input/Output interfacing – LCD and LED
5.1 8051 Input/Output interfacing – LCD and LED
5.1 8051 Input/Output interfacing – LCD and LED

2.1 16x2 LCD : Registers


 The 16X2 LCD has two built in registers namely data register and
command register.
 Command Register - stores the command instructions
given to the LCD.
A command is an instruction given to LCD to do a
predefined task like initializing, clearing the screen, setting the
cursor position, controlling display etc.

 Data Register - stores the data to be displayed on the LCD.


The data is the ASCII value of the character to be
displayed on the LCD.
5.1 8051 Input/Output interfacing – LCD and LED

Note: Identify which port is connected to Command/data lines


and which port pins to RS, R/W, E
5.1 8051 Input/Output interfacing – LCD and LED

3.1 Commands for an LCD display


Two rows of LCD are accessed using the cursor position to the
respective location given as 8 bits.
Row 0 starts from 80 and goes until 8F
Row 1 starts from C0 and goes until CF.
5.1 8051 Input/Output interfacing – LCD and LED
5.1 8051 Input/Output interfacing – LCD and LED

3.2 Programming an LCD display


STEP1: Initialization of LCD.

STEP2: Sending command to LCD.

STEP3: Writing the data to LCD.


5.1 8051 Input/Output interfacing – LCD and LED

3.2 Programming an LCD display


Step1: LCD initialization (common for almost all applications)
1. Send 38H to the 8 bit data line for initialization

2. Send 0FH for making LCD ON, cursor ON and cursor blinking ON.

3. Send 06H for incrementing cursor position.

4. Send 01H for clearing the display and return the cursor.
5.1 8051 Input/Output interfacing – LCD and LED

3.2 Programming an LCD display


Step2: Sending command to LCD
Send the command data to command register
Make R/W low.
Make RS=0 if data byte is a command
Pulse E from high to low with some delay.
Repeat above steps for sending another data.
5.1 8051 Input/Output interfacing – LCD and LED

3.2 Programming an LCD display


Step3: Writing the data to LCD
Place data byte on the data register.
Make R/W low.
make RS=1 if the data byte is a data to be displayed.
Pulse E from high to low with some delay.
Repeat above steps for sending another data.
5.1 8051 Input/Output interfacing – LCD and LED

Problem 1: Write an 8051 assembly language program to


display the message “N” and “O” on LCD display.
; IN this problem, the LCD’s 8 bit command/data lines are
connected to P1’s 8 lines. P2 is used for RS, R/W, E pins.
;call a time delay before sending next data/command
;P1.0-P1.7 are connected to LCD data pins D0-D7
;P2.0 is connected to RS pin of LCD
;P2.1 is connected to R/W pin of LCD
;P2.2 is connected to E pin of LCD
5.1 8051 Input/Output interfacing – LCD and LED
Problem 1: Write an 8051 assembly language program to display
the message “N” and “O” on LCD display.
ORG 0000H
MOV A, #38H ; INITIALIZE 2x16 LCD
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #0EH ; display on, cursor on
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #01 ; clear LCD
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #06H ; shift cursor right
ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
5.1 8051 Input/Output interfacing – LCD and LED
Problem 1: Write an 8051 assembly language program to display
the message “N” and “O” on LCD display.

MOV A, #84H ; cursor at line 1, pos. 4


ACALL COMNWRT ; call command subroutine
ACALL DELAY ; give LCD some time
MOV A, #’N’ ; display letter N
ACALL DATAWRT ; call display subroutine
ACALL DELAY ; give LCD some time
MOV A, #’O’ ; display letter O
ACALL DATAWRT ; call display subroutine
AGAIN: SJMP AGAIN ; stay here
5.1 8051 Input/Output interfacing – LCD and LED
Problem 1: Write an 8051 assembly language program to display
the message “N” and “O” on LCD display.

COMNWRT: ; send command to LCD


MOV P1, A ; copy reg A to port 1
CLR P2.0 ; RS=0 for command
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
5.1 8051 Input/Output interfacing – LCD and LED
Problem 1: Write an 8051 assembly language program to display
the message “N” and “O” on LCD display.

DATAWRT: ; write data to LCD


MOV P1, A ; copy reg A to port 1
SETB P2.0 ; RS=1 for data
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
5.1 8051 Input/Output interfacing – LCD and LED
Problem 1: Write an 8051 assembly language program to display
the message “N” and “O” on LCD display.

DELAY: MOV R3, #50 ; 50 or higher for fast CPUs


HERE2: MOV R4, #255 ; R4 = 255
HERE: DJNZ R4, HERE ; stay until R4 becomes 0
DJNZ R3, HERE2 ; stay until R3 becomes 0
RET
END
5.1 8051 Input/Output interfacing – LCD and LED

Problem 2: Write an 8051 assembly language program to


display the message “HELLO” on LCD display using DPTR. ;
P1.0-P1.7=D0-D7, P2.0=RS, P2.1=R/W, P2.2=E
ORG 0000H
MOV DPTR, #MYCOM ; Address of Initializing comm : #MYCOM
C1: CLR A
MOVC A,@A+DPTR ; Load command(byte) to A
ACALL COMNWRT ; Write command to LCD
ACALL DELAY ; Provide some delay
INC DPTR ; Increment to next command’s address
JZ SEND_DAT ; End of command is a zero; Check that
SJMP C1 ; If not the end of command, next command
5.1 8051 Input/Output interfacing – LCD and LED
Problem 2: Write an 8051 assembly language program to display the
message “HELLO” on LCD display using DPTR. ; P1.0-P1.7=D0-D7,
P2.0=RS, P2.1=R/W, P2.2=E
SEND_DAT: ; End of Commands, send data
MOV DPTR, #MYDATA; Address of First byte of Message
D1: CLR A ; Clear A
MOVC A,@A+DPTR ; Move the letter(byte) to A
ACALL DATAWRT ; Write byte(letter) to LCD
ACALL DELAY ; Delay after DATAWRT
INC DPTR ; Increment to next address
JZ AGAIN ; End of Data is 0
SJMP D1 ; If not End of Data, next character
AGAIN: SJMP AGAIN ; If end of Data, then Just wait
5.1 8051 Input/Output interfacing – LCD and LED
Problem 2: Write an 8051 assembly language program to display the
message “HELLO” on LCD display using DPTR. ; P1.0-P1.7=D0-D7,
P2.0=RS, P2.1=R/W, P2.2=E
COMNWRT: ; send command to LCD
MOV P1, A ; copy reg A to P1
CLR P2.0 ; RS=0 for command
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
5.1 8051 Input/Output interfacing – LCD and LED
Problem 2: Write an 8051 assembly language program to display the
message “HELLO” on LCD display using DPTR. ; P1.0-P1.7=D0-D7,
P2.0=RS, P2.1=R/W, P2.2=E
DATAWRT: ; send DATA to LCD
MOV P1, A ; copy reg A to P1
SETB P2.0 ; RS=1 for Data
CLR P2.1 ; R/W=0 for write
SETB P2.2 ; E=1 for high pulse
ACALL DELAY ; give LCD some time
CLR P2.2 ; E=0 for H-to-L pulse
RET
5.1 8051 Input/Output interfacing – LCD and LED
Problem 2: Write an 8051 assembly language program to display the
message “HELLO” on LCD display using DPTR. ; P1.0-P1.7=D0-D7,
P2.0=RS, P2.1=R/W, P2.2=E
DELAY: MOV R3, #250 ; 50 or higher for fast CPUs
HERE2: MOV R4, #255 ; R4 = 255
HERE: DJNZ R4, HERE ; stay until R4 becomes 0
DJNZ R3, HERE2
RET

ORG 300H
MYCOM: DB 38H, 0EH, 01, 06, 84H, 0 ; commands and null
MYDATA: DB “HELLO”, 0 ; Data is stored
END

You might also like