SlideShare a Scribd company logo
LCD interfacing with 8051
8051 Microcontroller
LCD 2 X16
1 2 3 4 5 6 7 8 9 10
1112131415
🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
GND VCC CONT RS
R/
W
EN D0 D1 D2 D3 D4 D5 D6 D7 BL
4-Apr-20
Pin No.
Symbol
LCD 2 X16 (Features)
Y
.
C
.
C
.
E
.
N
A
G
P
U
R
(
M
.
S
.
)
LCD Display RAM
With address
80H
81H
82H
83H
84H
85H
86H
87H
88H
89H
8AH
8BH
8CH
8DH
8EH
8FH
C0H
C1H
C2H
C3H
C4H
C5H
86H
C7H
C8H
C9H
CAH
CBH
CCH
CDH
CEH
CFH
4-Apr-20
LCD 2 X16 (Features)
5 x 7 dots plus cursor, 5 x 10 dots per
character 4 or 8 bit interface with MPU is
possible
Display Data RAM (DR) : 80 x 8 bit, Max 80 characters
Character Generator (CG) ROM : 160, 5 x 7 Character fonts
32, 5 x 10 Character fonts
Custom ROM codes
available
Character Generator RAM : Program write (64 x 8 bits)
8, 5 x 7 Character fonts
4, 5 x 10 Character fonts
Both Display Data RAM & CG RAM can be read by
MPU Wide variety of operating instructions :
Display Clear, Cursor
Home, Display ON / OFF, Display Cursor Blink,
Cursor shift, display shift etc.
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
4-Apr-20
LCD 2 X16 (Pin Description)
4-Apr-20
Signal In/Out Function
D7 – D0 I / O
8 bit data bus used for bi-directional
data
transfer between µC & LCD module
D7 – D4 I / O
These lines are used as data bus in 4
bit operation.
D7 O Can be used as Busy Flag
RS I
Register Select
0 = Instruction Register (IR)
1 = Data Register (DR)
R / W I
Signal to select Read or Write
0 = Write, 1 = Read
EN I
Enable signal to start read / write
operation
LCD 2 X16 (Registers)
RS R / W Operation
0 0
IR write, internal operation (Display clear,
cursor position, function set etc.)
0 1 Busy Flag (D7) & address counter (D6-D0) read
1 0 DR write, internal operation (DD RAM or CG RAM)
1 1 DR read, internal operation (DD RAM or CG RAM)
Controller for LCD has two 8 bit registers, the instruction
register (IR) and data register (DR)
IR is write only register used to store only instruction codes like
display Clear, cursor shift or address of DD RAM etc.
DR is read / write register used to store temporary data into DD
RAM or CG RAM by an internal operation of the display controller.
If BF=1, then module is performing internal operation
and next instruction will not be accepted
4-Apr-20
Interfacing LCD (8 bit data
length)
P2.7
P2.6
P2.5
P2.4
P2.3
P2.2
P2.1
P2.0
P0.5
P0.6
P0.7
8051
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
+ 5V
+ 5V
1K
IR
DR
LCD
4-Apr-20
Interfacing LCD (4 bit data
length )
P0.3
P0.2
P0.1
P0.0
P1.3
P0.5
P0.4
8051
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
+ 5V
1K
+ 5V
IR
DR
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
LCD
4-Apr-20
Write Operation (IR)
IR
DR
0
0
#dat
a
IR
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
LCD
To write data into
IR
1. Select instruction Reg. (RS = 0)
2. Select write (R/W = 0)
3. Transfer instruction code to
Port ( Via Data bus)
4. Enable signal to start
write operation (EN = 1)
CLR RS
CLR RW
MOV Port, #
data SETB
EN
ACALL delay_1ms
CLR EN
ACALL
delay_5ms
Sub program to write data into
IR
4-Apr-20
Write Operation (DR)
IR
DR
0
1
#dat
a
DR
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
LCD
To write data into
DR
1. Select Data Reg. (RS = 1)
2. Select write (R/W = 0)
3. Transfer ASCII code of
display character to Port
4. Enable signal to start
write operation (EN = 1)
SETB RS
CLR RW
MOV Port, #
data SETB
EN
ACALL delay_1ms
CLR EN
ACALL
delay_5ms
Sub program to write data into
DR
4-Apr-20
LCD instructions (8 bit instr.
code)
1. Function Set:
DL = Data Length (If DL=1, 8 bit & If DL=0, 4 bit)
N = No. of display lines (If N=0, 1 Line & If N=1, 2 Line)
F = Character Font (If F=0, 5x7 dot character font & F=1,
5x10
2. Display ON/OFF Control:
D = 0 ; Display OFF & D = 1 ; Display ON
C = 0 ; Cursor OFF & C = 1 ; Cursor ON
B = 0 ; Blink OFF & B = 1 ;
Blink ON
3. Clear Display
4. Entry Mode Set:
I/D = 1 ; Increment Mode ( Increment DD RAM address
by 1) S = 0 ; No display shift operation
5. Set DD RAM address:
Sets the address counter to the DD RAM address
AAAAAAA. Data is then written / read to from the DD
RAM.
For 2 line display module
AAAAAAA = 00H to 27H for the first line &
40H to 67H for the second line.
4-Apr-20
LCD instructions…
1. Function
Set
D7
0 0 1 DL N F X X
4-Apr-20
D6 D5 D4 D3 D2 D1 D0
DL: Sets interface data length
If DL = 1, data is sent or received in 8 bit length (D7 – D0).
if DL = 0, data is sent or received in 4 bit length (D7 – D4).
When 4 bit length is selected data must be sent or received
twice.
N: Sets the number of
lines If N = 0 ; 1 line
display If N = 1 ; 2 line
display
F: Sets character font
If F = 1 ; 5 x 10
dots
If F = 0 ; 5 x 7 dots
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
⯀⯀⯀⯀⯀
e.g. For 8 bit data length, 2
line display, 5 x 7 dots.
Function Set = 0011 1000 = 38H
LCD instructions…
2. Display ON/OFF
Control
D7
D6
D5
0 0 0 0 1 D C B
D0
D1
D2
D3
D4
D : If D = 1, display is ON. If D = 0, display is OFF
C : If C = 1, cursor is displayed. If C = 0, cursor is not
displayed. B : If B = 1, Cursor blink is ON, If B = 0, Cursor
blink is OFF.
e.g. For Display ON, Cursor display &
blinking.
Display ON = 0000 1111 = 0FH
3. Clear
Display
D7
0 0 0 0 0 0 0 1
4-Apr-20
D0
D1
D2
D3
D4
D5
D6
= 01H
Writes the space code “20H” into all addresses of DD RAM.
LCD instructions…
4. Entry Mode
Set
D7
0 0 0 0 0 1 I/D S
4-Apr-20
D6 D5 D4 D3 D2 D1 D0
Sets the increment / decrement and shift modes to the desired
settings.
I/D : Increments (I/D = 1) or decrements (I/D = 0) the DD RAM
address by 1 when a character code is written or read
from the DD RAM. The cursor moves to the right when
incremented by +1
S : Shift the entire display either to the right or to the left when S =
1.
If I/D = 1, shift to the right. If I/D = 0, shift to the left.
e.g. DD RAM address should be incremented, No display
shift.
Entry Mode Set = 0000 0110 = 06H
LCD instructions…
5. Set DD RAM Address
D7
D6
1 A A A A A A A
4-Apr-20
D5 D4 D3 D2 D1 D0
Sets the address counter to the DD RAM address AAAAAAA. Data is
then written / read to from the DD RAM.
For 2 line display module AAAAAAA = 00H to 27H for the first line &
40H to 67H for the second line.
e.g. To display characters in the first line
Set DD RAM address = 1000 0000 = 80H
e.g. To display characters in the second
line
Set DD RAM address = 1100 0000 = C0H
Summary of LCD instructions
Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0
Function Set 0 0 0 0 1 DL N F X X
Display ON/OFF 0 0 0 0 0 0 1 D C B
Clear Display 0 0 0 0 0 0 0 0 0 1
Entry Mode Set 0 0 0 0 0 0 0 1 I/D S
Set DD RAM
address
0 0 1 A A A A A A A
Write data to
DD RAM
1 0 Write data
Read data
from DD RAM
1 1 Read data
4-Apr-20
Initialization of LCD (8 bit)
4-Apr-20
Initialization Flowchart
Send Function Set to IR ; Initialize LCD
; Send Function
Set
; instruction 3
times
; wait for 5 msec
;Send Function Set
instruction
; wait for 5 msec
Wait for more than 4.1
msec
Send Function Set to IR
Send Function Set to IR ;Send Function Set
Instruction
; Read & Check Busy Flag
Wait for 100 usec
D7 1
4-Apr-20
Initialization Flowchart …
Send Function Set to IR
D7 1
Send Display OFF to IR
; ;Send Function Set
Instruction
; Check busy flag (D7=0)
; Display OFF
instruction
; Check busy flag
(D7=0)
; Clear Display
Instruction
; Check busy flag (D7=0)
D7 1
Send Clear Display to IR
D7 1
4-Apr-20
Initialization Flowchart …
Send Entry Mode to IR
D7 1
Send Display ON to
IR
; ;Send Entry Mode
Instruction
; Check busy flag (D7=0)
; Display ON instruction
; Check busy flag
(D7=0)
; Initialization Done
; Send Display RAM
Address
; and data
D7 1
Initialization is
Complete Display
is Ready
4-Apr-20
Check Busy Flag OR Delay
D7 1
Send Instruction to IR
;Before sending instruction /
Command you can check
Busy Flag Status (D7=0)
Send Instruction to IR
4-Apr-20
;Before sending instruction /
Command you can give delay
of 5 msec
OR
Delay of 5 msec
Initialization of LCD (4 bit)
4-Apr-20
LCD Program #1
 Interface 2X16 LCD with 8051.Use 8 bit data length and write
program to display “Y” in first line. Use P2 for data pins and P0
for control pins
P2.7
P2.6
P2.5
P2.4
P2.3
P2.2
P2.1
P2.0
P0.5
P0.6
P0.7
8051
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
+ 5V
+ 5V
1K
IR
DR
LCD
4-Apr-20
LCD instructions Setting
1. Function
Set
D7
0 0 1 DL N F X X
D6 D5 D4 D3 D2 D1 D0
DL = 1
N = 1
F = 0
; data is sent or received in 8 bit length (D7 –
D0).
; 2 line display
; 5 x 7 dots
Function Set = 38H
0 0 1 1 1 0 0 0
4-Apr-20
LCD instructions Setting
2. Display ON/OFF
Control
D7
D6
D5
D0
D1
D2
D3
D4
0 0 0 0 1 D C B
D = 1 ;display is ON
C = 1 ;cursor is
displayed B = 1 ;Cursor
blink
Display ON Control = 0FH
3. Clear
Display
D7
0 0 0 0 0 0 0 1
D0
D1
D2
D3
D4
D5
D6
= 01H
0 0 0 0 1 1 1 1
Display OFF Control = 08H
0 0 0 0 1 0 0 0
4-Apr-20
LCD instructions Setting
4. Entry Mode
Set
D7
0 0 0 0 0 1 I/D S
D6 D5 D4 D3 D2 D1 D0
I/D =
1
;Increments the DD RAM address by 1 when a character
code is
;written or read from the DD RAM.
;The cursor moves to the right when incremented by +1
S = 0 ; No display shift
Entry Mode Set = 06H
0 0 0 0 0 1 1 0
4-Apr-20
LCD instructions Setting
4-Apr-20
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
5. DD RAM Address
DD
RAM
Addr
ess
Y
LCD
displa
y
e.g. To display characters in the first line, first
position
Set DD RAM address = 1000 0000 = 80H
Flowchart
Send 38H to IR ; Initialize LCD
; Send Function
Set
; instruction 3
times
; wait for 5 msec
;Send Function Set
instruction
; wait for 5 msec
Wait for more than 4.1
msec
Send 38H to IR
Send 38H to IR ;Send Function Set
Instruction
; Read & Check Busy Flag
Wait for 100 usec
D7 1
4-Apr-20
Flowchart …
Send 38H to IR
D7 1
Send 08H to
IR
; ;Send Function Set
Instruction
; Check busy flag
(D7=0)
; Display OFF
instruction
; Check busy flag
(D7=0)
; Clear Display
Instruction
; Check busy flag
(D7=0)
D7 1
Send 01H to IR
D7 1
4-Apr-20
Flowchart …
Send 06 H to IR
D7 1
Send 0FH to IR
; ;Send Entry Mode
Instruction
; Check busy flag (D7=0)
; Display ON instruction
; Check busy flag
(D7=0)
; Initialization Done
; Send Display RAM
Address
; and data
D7 1
Initialization is
Complete Display
is Ready
4-Apr-20
Flowchart…
D7
; Check busy flag
(D7=0)
1
Send 80H to IR
; DD RAM Address
: First Line, first
position
D7
; Check busy flag
(D7=0)
1
Send „Y” to DR ; ASCII CODE OF „Y‟
STOP
4-Apr-20
Program #1
4-Apr-20
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
ACALL CHK_BUSY
MOV A, #38H
ACALL COMM
ACALL CHK_BUSY
MOV A, #08H
ACALL COMM
ACALL CHK_BUSY
MOV A, #01H
ACALL COMM
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Check Busy Flag (D7 =0) then send
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Display OFF (0000 1 D C B)
; Clear
Display
Program #1 …
4-Apr-20
ACALL CHK_BUSY
MOV A, #06H
ACALL COMM
ACALL CHK_BUSY
MOV A, #0FH
ACALL COMM
ACALL CHK_BUSY
MOV A, #80H
ACALL COMM
ACALL CHK_BUSY
MOV A, #’Y’
ACALL DISP
L1: SJMP L1
; Entry mode: increment (0000 01 I/D
S)
; Display ON (0000 1 D C B), CURSOR BLINK
; DD RAM Address (First Line, first
position)
; ASCII CODE OF „Y‟
; Subroutine to send data to
DR
; Terminate Program
Sub Programs #1
4-Apr-20
; Subroutine to check Busy Flag
CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction
Register) SETB P0.6 ; RW=1, READ IR
MOV A, P2 ; Read Data from IR
(D7=Busy Flag) (D7=1, Busy)
BUSY: JB ACC.7, BUSY
RET
; Check Busy Flag
status
; Busy Flag = 0
; Subroutine to send data to IR (Instruction Register)
; EN=0
; RS= 0, Register select (IR)
; RW=0, WRITE
; Send Data to IR
; EN=1
COMM: CLR P0.5
CLR P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR
P0.5 RET
; EN=0
Sub Programs #1…
4-Apr-20
; Subroutine to send data to DR (Data Register)
DISP: ; EN=0
; RS= 1, Register select (DR)
; RW=0, WRITE
; Send Data to DR
; EN=1
CLR P0.5
SETB P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR P0.5
RET
; EN=0
; Subroutine for Delay of 5 msec
delay_5ms: MOV R0, #0AH
L2: MOV R1, #0FEH
L3: DJNZ R1, L3
DJNZ R0, L2
RET
; N = 10
; N = 254
; Decrement R1& JNZ
; Decrement R0& JNZ
LCD Program #2
 Interface 2X16 LCD with 8051.Use 8 bit data length and write
program to display “HELLO” in first line. Use P2 for data pins
and P0 for control pins
P2.7
P2.6
P2.5
P2.4
P2.3
P2.2
P2.1
P2.0
P0.5
P0.6
P0.7
8051
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
+ 5V
+ 5V
1K
IR
DR
LCD
4-Apr-20
LCD instructions Setting
4-Apr-20
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
DD RAM Address
DD
RAM
Addr
ess
H E L L O
LCD
displa
y
e.g. To display characters in the first line, first
position
Set DD RAM address = 1000 0000 = 80H
Flowchart
Send 38H to IR ; Initialize LCD
; Send Function
Set
; instruction 3
times
; wait for 5 msec
;Send Function Set
instruction
; wait for 5 msec
Wait for more than 4.1
msec
Send 38H to IR
Send 38H to IR ;Send Function Set
Instruction
; Read & Check Busy Flag
Wait for 100 usec
D7 1
4-Apr-20
Flowchart …
Send 38H to IR
D7 1
Send 08H to
IR
; ;Send Function Set
Instruction
; Check busy flag
(D7=0)
; Display OFF
instruction
; Check busy flag
(D7=0)
; Clear Display
Instruction
; Check busy flag
(D7=0)
D7 1
Send 01H to IR
D7 1
4-Apr-20
Flowchart …
Send 06 H to IR
D7 1
Send 0FH to IR
; ;Send Entry Mode
Instruction
; Check busy flag (D7=0)
; Display ON instruction
; Check busy flag
(D7=0)
; Initialization Done
; Send Display RAM
Address
; and data
D7 1
Initialization is
Complete Display
is Ready
4-Apr-20
Flowchart…
D7
; Check busy flag
(D7=0)
1
Send 80H to IR
; DD RAM Address
: First Line, first
position
D7
; Check busy flag
(D7=0)
1
Send „H” to DR ; ASCII CODE OF „H‟
Send „E” to DR ; ASCII CODE OF „E‟
4-Apr-20
Flowchart…
Send „L” to DR ; ASCII CODE OF „L‟
Send „O” to DR ; ASCII CODE OF „O‟
Send „L” to DR ; ASCII CODE OF „L‟
STOP
4-Apr-20
Program #2
4-Apr-20
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
ACALL CHK_BUSY
MOV A, #38H
ACALL COMM
ACALL CHK_BUSY
MOV A, #08H
ACALL COMM
ACALL CHK_BUSY
MOV A, #01H
ACALL COMM
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Check Busy Flag (D7 =0) then send
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Display OFF (0000 1 D C B)
; Clear
Display
Program #2
4-Apr-20
ACALL CHK_BUSY
MOV A, #06H
ACALL COMM
ACALL CHK_BUSY
MOV A, #0FH
ACALL COMM
ACALL CHK_BUSY
MOV A, #80H
ACALL COMM
; Entry mode: increment (0000 01 I/D
S)
; Display ON (0000 1 D C B), CURSOR BLINK
; DD RAM Address (First Line, first
position)
ACALL CHK_BUSY
MOV A, #’H’
ACALL DISP
MOV A, #’E’
ACALL DISP
MOV A, #’L’
ACALL DISP
MOV A, #’L’
ACALL DISP
MOV A, #’O‟
ACALL DISP
L1: SJMP L1
; ASCII CODE OF „H‟
; Subroutine to send data to
DR
; ASCII CODE OF „E‟
; Subroutine to send data to
DR
; ASCII CODE OF „L‟
; Subroutine to send data to
DR
; ASCII CODE OF „L‟
; Subroutine to send data to
DR
; ASCII CODE OF „O‟
Sub Programs #2
4-Apr-20
; Subroutine to check Busy Flag
CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction
Register) SETB P0.6 ; RW=1, READ IR
MOV A, P2 ; Read Data from IR
(D7=Busy Flag) (D7=1, Busy)
BUSY: JB ACC.7, BUSY
RET
; Check Busy Flag
status
; Busy Flag = 0
; Subroutine to send data to IR (Instruction Register)
; EN=0
; RS= 0, Register select (IR)
; RW=0, WRITE
; Send Data to IR
; EN=1
COMM: CLR P0.5
CLR P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR
P0.5 RET
; EN=0
Sub Programs #2
4-Apr-20
; Subroutine to send data to DR (Data Register)
DISP: ; EN=0
; RS= 1, Register select (DR)
; RW=0, WRITE
; Send Data to DR
; EN=1
CLR P0.5
SETB P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR P0.5
RET
; EN=0
; Subroutine for Delay of 5 msec
delay_5ms: MOV R0, #0AH
L2: MOV R1, #0FEH
L3: DJNZ R1, L3
DJNZ R0, L2
RET
; N = 10
; N = 254
; Decrement R1& JNZ
; Decrement R0& JNZ
LCD Program #3
 Interface 2X16 LCD with 8051.Use 8 bit data length and write
program to display “WELCOME” in first line. Use P2 for data pins and P0
for control pins
P2.7
P2.6
P2.5
P2.4
P2.3
P2.2
P2.1
P2.0
P0.5
P0.6
P0.7
8051
15(BL)
14(D7)
13(D6)
12(D5)
11(D4)
10(D3)
9(D2)
8(D1)
7(D0)
6(EN)
5(R/W)
4(RS)
3(CONT)
2(VCC)
1(GND)
+ 5V
+ 5V
1K
IR
DR
LCD
4-Apr-20
LCD display
4-Apr-20
80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F
C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF
 DD RAM Address
DD
RAM
Addr
ess
W E L C O M E
LCD
displa
y
e.g. To display characters in the first line, first
position
Set DD RAM address = 1000 0000 = 80H
LCD Program #3
W
E
L
C
O
M
E
0200H
0201H
0202H
0203H
0204H
0205H
0206H
00
R5
0200
 ASCII codes of characters are transferred from program memory
to Display RAM
A
DPTR
W
E
L
C
O
M
E
Display RAM
80H
81H
82H
83H
84H
85H
86H
Program Memory
Instructions
4-Apr-20
MOV A, R5
MOVC A, @ A + DPTR
ACALL DISP
INC R5
LCD Program #3 …
 Data Transfer Logic
; Initialise Base Address,
; Index, Counter
; Transfer index to ACC
; Use MOVC to read data
; Send data to Display RAM
; Increment index for nest Char
;Decrement the Counter and
;repeat till Counter is 0
DPTR = 0200H Base address
R5 = 00 index, R6 = 7 counter,
MOV A, R5
MOVC A, @A + DPTR
Send Data of A to DR
INC R5
DEC R6 & Repeat if R6 not
0
4-Apr-20
Program #3
4-Apr-20
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
MOV A, #38H
ACALL COMM
ACALL delay_5ms
ACALL CHK_BUSY
MOV A, #38H
ACALL COMM
ACALL CHK_BUSY
MOV A, #08H
ACALL COMM
ACALL CHK_BUSY
MOV A, #01H
ACALL COMM
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Check Busy Flag (D7 =0) then send
; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7
font
; Display OFF (0000 1 D C B)
; Clear
Display
Program #3
4-Apr-20
ACALL CHK_BUSY
MOV DPTR, #0200H ; Base address of Look up table
MOV R5, #00H ; Index first element of message string
MOV R6, #07H ; R6 is counter for 7 characters to
display
L4: MOV A, R5 ; Index
MOVC A, @A+DPTR ; Get ASCII code of character in ACC
ACALL DISP ; Subroutine to send data to DR
INC R5 ; Increment Index
DJNZ R6, L4 ; Decrement Counter
L5: SJMP L5 ; Terminate the Program
ORG 0200H
DB „WELCOME‟
ACALL CHK_BUSY
MOV A, #06H
ACALL COMM
ACALL CHK_BUSY
MOV A, #0FH
ACALL COMM
ACALL CHK_BUSY
MOV A, #80H
ACALL COMM
; Entry mode: increment (0000 01 I/D
S)
; Display ON (0000 1 D C B), CURSOR BLINK
; DD RAM Address (First Line, first
position)
Sub Programs #3
4-Apr-20
; Subroutine to check Busy Flag
CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction
Register) SETB P0.6 ; RW=1, READ IR
MOV A, P2 ; Read Data from IR
(D7=Busy Flag) (D7=1, Busy)
BUSY: JB ACC.7, BUSY
RET
; Check Busy Flag
status
; Busy Flag = 0
; Subroutine to send data to IR (Instruction Register)
; EN=0
; RS= 0, Register select (IR)
; RW=0, WRITE
; Send Data to IR
; EN=1
COMM: CLR P0.5
CLR P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR
P0.5 RET
; EN=0
Sub Programs #3
4-Apr-20 ptkarule@ycce.edu
; Subroutine to send data to DR (Data Register)
DISP: ; EN=0
; RS= 1, Register select (DR)
; RW=0, WRITE
; Send Data to DR
; EN=1
CLR P0.5
SETB P0.7
CLR P0.6
MOV P2, A
SETB P0.5
NOP
NOP
NOP
CLR P0.5
RET
; EN=0
; Subroutine for Delay of 5 msec
delay_5ms: MOV R0, #0AH
L2: MOV R1, #0FEH
L3: DJNZ R1, L3
DJNZ R0, L2
RET
; N = 10
; N = 254
; Decrement R1& JNZ
; Decrement R0& JNZ
8051 Microcontroller
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students
8051_interface_LCD.pptx iii ece III ECE MPMC  jntu k syllabus this is very help to ECE Students

More Related Content

PPTX
131080111003 mci
PPT
Lcd interface with atmega32 avr best.ppt
PDF
Analog to Digital Converter
PPTX
KEYBOARD/DISPLAY CONTROLLER INTEL 8279.pptx
DOCX
Lcd interfacing
DOCX
Alp lcd
PPTX
LCD_Example.pptx
PDF
Lcd tutorial for interfacing with microcontrollers basics of alphanumeric lc...
131080111003 mci
Lcd interface with atmega32 avr best.ppt
Analog to Digital Converter
KEYBOARD/DISPLAY CONTROLLER INTEL 8279.pptx
Lcd interfacing
Alp lcd
LCD_Example.pptx
Lcd tutorial for interfacing with microcontrollers basics of alphanumeric lc...

Similar to 8051_interface_LCD.pptx iii ece III ECE MPMC jntu k syllabus this is very help to ECE Students (20)

PDF
Interfacing with LCD
PPTX
LCD Interacing with 8051
PDF
Lecture mp 7(interface)
DOCX
Lcd display
PDF
Lcd tutorial
PDF
MODULO TS-12864A-2
DOC
Moving message display
PPT
Display11 in mp
PPTX
Micro c lab6(lcd)
PPT
VGA VHDL RTL design tutorial
PDF
Hd44780a00 dtasheet
PPTX
Computer Organization
PDF
08_lcd.pdf
PPT
Introduction to Microprocessor & Microcontroller.ppt
PDF
Lcd12 a64
DOCX
SIMPLE Frequency METER using AT89c51
PPTX
Basic computer organization design
PDF
ARM LCD Interfacing
PPTX
LCD interfacing
PPTX
26. 8255 control word programming
Interfacing with LCD
LCD Interacing with 8051
Lecture mp 7(interface)
Lcd display
Lcd tutorial
MODULO TS-12864A-2
Moving message display
Display11 in mp
Micro c lab6(lcd)
VGA VHDL RTL design tutorial
Hd44780a00 dtasheet
Computer Organization
08_lcd.pdf
Introduction to Microprocessor & Microcontroller.ppt
Lcd12 a64
SIMPLE Frequency METER using AT89c51
Basic computer organization design
ARM LCD Interfacing
LCD interfacing
26. 8255 control word programming
Ad

More from Kishore5511 (7)

PPTX
8051_interface_DAC.pptx for iii ece III ECE MPMC jntu k syllabus this is ver...
PDF
es unit-4 material as per jntuk syllanus
PDF
ES unit 6unit aterial for students as per JNTUK
PDF
phone software input keys material es unit-4 material as per jntuk syllanus
PDF
es unit-4 material as per jntuk syllanus
PDF
test on host machine it is embedded systems 5 unit topic
PDF
Iot lecture notes_hyd
8051_interface_DAC.pptx for iii ece III ECE MPMC jntu k syllabus this is ver...
es unit-4 material as per jntuk syllanus
ES unit 6unit aterial for students as per JNTUK
phone software input keys material es unit-4 material as per jntuk syllanus
es unit-4 material as per jntuk syllanus
test on host machine it is embedded systems 5 unit topic
Iot lecture notes_hyd
Ad

Recently uploaded (20)

PPTX
UNIT - 3 Total quality Management .pptx
PPT
Total quality management ppt for engineering students
PPT
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
PDF
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
PPT
Occupational Health and Safety Management System
PDF
86236642-Electric-Loco-Shed.pdf jfkduklg
PDF
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
PPTX
Current and future trends in Computer Vision.pptx
PDF
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
PDF
Abrasive, erosive and cavitation wear.pdf
PPT
introduction to datamining and warehousing
PDF
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
PDF
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
PPT
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
PDF
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
PDF
Exploratory_Data_Analysis_Fundamentals.pdf
PDF
III.4.1.2_The_Space_Environment.p pdffdf
PDF
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
PDF
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PDF
PPT on Performance Review to get promotions
UNIT - 3 Total quality Management .pptx
Total quality management ppt for engineering students
A5_DistSysCh1.ppt_INTRODUCTION TO DISTRIBUTED SYSTEMS
Human-AI Collaboration: Balancing Agentic AI and Autonomy in Hybrid Systems
Occupational Health and Safety Management System
86236642-Electric-Loco-Shed.pdf jfkduklg
COURSE DESCRIPTOR OF SURVEYING R24 SYLLABUS
Current and future trends in Computer Vision.pptx
SMART SIGNAL TIMING FOR URBAN INTERSECTIONS USING REAL-TIME VEHICLE DETECTI...
Abrasive, erosive and cavitation wear.pdf
introduction to datamining and warehousing
Enhancing Cyber Defense Against Zero-Day Attacks using Ensemble Neural Networks
Analyzing Impact of Pakistan Economic Corridor on Import and Export in Pakist...
INTRODUCTION -Data Warehousing and Mining-M.Tech- VTU.ppt
keyrequirementskkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkkk
Exploratory_Data_Analysis_Fundamentals.pdf
III.4.1.2_The_Space_Environment.p pdffdf
BIO-INSPIRED ARCHITECTURE FOR PARSIMONIOUS CONVERSATIONAL INTELLIGENCE : THE ...
null (2) bgfbg bfgb bfgb fbfg bfbgf b.pdf
PPT on Performance Review to get promotions

8051_interface_LCD.pptx iii ece III ECE MPMC jntu k syllabus this is very help to ECE Students

  • 1. LCD interfacing with 8051 8051 Microcontroller
  • 2. LCD 2 X16 1 2 3 4 5 6 7 8 9 10 1112131415 🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇🞇 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 GND VCC CONT RS R/ W EN D0 D1 D2 D3 D4 D5 D6 D7 BL 4-Apr-20 Pin No. Symbol
  • 3. LCD 2 X16 (Features) Y . C . C . E . N A G P U R ( M . S . ) LCD Display RAM With address 80H 81H 82H 83H 84H 85H 86H 87H 88H 89H 8AH 8BH 8CH 8DH 8EH 8FH C0H C1H C2H C3H C4H C5H 86H C7H C8H C9H CAH CBH CCH CDH CEH CFH 4-Apr-20
  • 4. LCD 2 X16 (Features) 5 x 7 dots plus cursor, 5 x 10 dots per character 4 or 8 bit interface with MPU is possible Display Data RAM (DR) : 80 x 8 bit, Max 80 characters Character Generator (CG) ROM : 160, 5 x 7 Character fonts 32, 5 x 10 Character fonts Custom ROM codes available Character Generator RAM : Program write (64 x 8 bits) 8, 5 x 7 Character fonts 4, 5 x 10 Character fonts Both Display Data RAM & CG RAM can be read by MPU Wide variety of operating instructions : Display Clear, Cursor Home, Display ON / OFF, Display Cursor Blink, Cursor shift, display shift etc. ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ 4-Apr-20
  • 5. LCD 2 X16 (Pin Description) 4-Apr-20 Signal In/Out Function D7 – D0 I / O 8 bit data bus used for bi-directional data transfer between µC & LCD module D7 – D4 I / O These lines are used as data bus in 4 bit operation. D7 O Can be used as Busy Flag RS I Register Select 0 = Instruction Register (IR) 1 = Data Register (DR) R / W I Signal to select Read or Write 0 = Write, 1 = Read EN I Enable signal to start read / write operation
  • 6. LCD 2 X16 (Registers) RS R / W Operation 0 0 IR write, internal operation (Display clear, cursor position, function set etc.) 0 1 Busy Flag (D7) & address counter (D6-D0) read 1 0 DR write, internal operation (DD RAM or CG RAM) 1 1 DR read, internal operation (DD RAM or CG RAM) Controller for LCD has two 8 bit registers, the instruction register (IR) and data register (DR) IR is write only register used to store only instruction codes like display Clear, cursor shift or address of DD RAM etc. DR is read / write register used to store temporary data into DD RAM or CG RAM by an internal operation of the display controller. If BF=1, then module is performing internal operation and next instruction will not be accepted 4-Apr-20
  • 7. Interfacing LCD (8 bit data length) P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 P0.5 P0.6 P0.7 8051 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) + 5V + 5V 1K IR DR LCD 4-Apr-20
  • 8. Interfacing LCD (4 bit data length ) P0.3 P0.2 P0.1 P0.0 P1.3 P0.5 P0.4 8051 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) + 5V 1K + 5V IR DR 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) LCD 4-Apr-20
  • 9. Write Operation (IR) IR DR 0 0 #dat a IR 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) LCD To write data into IR 1. Select instruction Reg. (RS = 0) 2. Select write (R/W = 0) 3. Transfer instruction code to Port ( Via Data bus) 4. Enable signal to start write operation (EN = 1) CLR RS CLR RW MOV Port, # data SETB EN ACALL delay_1ms CLR EN ACALL delay_5ms Sub program to write data into IR 4-Apr-20
  • 10. Write Operation (DR) IR DR 0 1 #dat a DR 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) LCD To write data into DR 1. Select Data Reg. (RS = 1) 2. Select write (R/W = 0) 3. Transfer ASCII code of display character to Port 4. Enable signal to start write operation (EN = 1) SETB RS CLR RW MOV Port, # data SETB EN ACALL delay_1ms CLR EN ACALL delay_5ms Sub program to write data into DR 4-Apr-20
  • 11. LCD instructions (8 bit instr. code) 1. Function Set: DL = Data Length (If DL=1, 8 bit & If DL=0, 4 bit) N = No. of display lines (If N=0, 1 Line & If N=1, 2 Line) F = Character Font (If F=0, 5x7 dot character font & F=1, 5x10 2. Display ON/OFF Control: D = 0 ; Display OFF & D = 1 ; Display ON C = 0 ; Cursor OFF & C = 1 ; Cursor ON B = 0 ; Blink OFF & B = 1 ; Blink ON 3. Clear Display 4. Entry Mode Set: I/D = 1 ; Increment Mode ( Increment DD RAM address by 1) S = 0 ; No display shift operation 5. Set DD RAM address: Sets the address counter to the DD RAM address AAAAAAA. Data is then written / read to from the DD RAM. For 2 line display module AAAAAAA = 00H to 27H for the first line & 40H to 67H for the second line. 4-Apr-20
  • 12. LCD instructions… 1. Function Set D7 0 0 1 DL N F X X 4-Apr-20 D6 D5 D4 D3 D2 D1 D0 DL: Sets interface data length If DL = 1, data is sent or received in 8 bit length (D7 – D0). if DL = 0, data is sent or received in 4 bit length (D7 – D4). When 4 bit length is selected data must be sent or received twice. N: Sets the number of lines If N = 0 ; 1 line display If N = 1 ; 2 line display F: Sets character font If F = 1 ; 5 x 10 dots If F = 0 ; 5 x 7 dots ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ ⯀⯀⯀⯀⯀ e.g. For 8 bit data length, 2 line display, 5 x 7 dots. Function Set = 0011 1000 = 38H
  • 13. LCD instructions… 2. Display ON/OFF Control D7 D6 D5 0 0 0 0 1 D C B D0 D1 D2 D3 D4 D : If D = 1, display is ON. If D = 0, display is OFF C : If C = 1, cursor is displayed. If C = 0, cursor is not displayed. B : If B = 1, Cursor blink is ON, If B = 0, Cursor blink is OFF. e.g. For Display ON, Cursor display & blinking. Display ON = 0000 1111 = 0FH 3. Clear Display D7 0 0 0 0 0 0 0 1 4-Apr-20 D0 D1 D2 D3 D4 D5 D6 = 01H Writes the space code “20H” into all addresses of DD RAM.
  • 14. LCD instructions… 4. Entry Mode Set D7 0 0 0 0 0 1 I/D S 4-Apr-20 D6 D5 D4 D3 D2 D1 D0 Sets the increment / decrement and shift modes to the desired settings. I/D : Increments (I/D = 1) or decrements (I/D = 0) the DD RAM address by 1 when a character code is written or read from the DD RAM. The cursor moves to the right when incremented by +1 S : Shift the entire display either to the right or to the left when S = 1. If I/D = 1, shift to the right. If I/D = 0, shift to the left. e.g. DD RAM address should be incremented, No display shift. Entry Mode Set = 0000 0110 = 06H
  • 15. LCD instructions… 5. Set DD RAM Address D7 D6 1 A A A A A A A 4-Apr-20 D5 D4 D3 D2 D1 D0 Sets the address counter to the DD RAM address AAAAAAA. Data is then written / read to from the DD RAM. For 2 line display module AAAAAAA = 00H to 27H for the first line & 40H to 67H for the second line. e.g. To display characters in the first line Set DD RAM address = 1000 0000 = 80H e.g. To display characters in the second line Set DD RAM address = 1100 0000 = C0H
  • 16. Summary of LCD instructions Instruction RS R/W D7 D6 D5 D4 D3 D2 D1 D0 Function Set 0 0 0 0 1 DL N F X X Display ON/OFF 0 0 0 0 0 0 1 D C B Clear Display 0 0 0 0 0 0 0 0 0 1 Entry Mode Set 0 0 0 0 0 0 0 1 I/D S Set DD RAM address 0 0 1 A A A A A A A Write data to DD RAM 1 0 Write data Read data from DD RAM 1 1 Read data 4-Apr-20
  • 17. Initialization of LCD (8 bit) 4-Apr-20
  • 18. Initialization Flowchart Send Function Set to IR ; Initialize LCD ; Send Function Set ; instruction 3 times ; wait for 5 msec ;Send Function Set instruction ; wait for 5 msec Wait for more than 4.1 msec Send Function Set to IR Send Function Set to IR ;Send Function Set Instruction ; Read & Check Busy Flag Wait for 100 usec D7 1 4-Apr-20
  • 19. Initialization Flowchart … Send Function Set to IR D7 1 Send Display OFF to IR ; ;Send Function Set Instruction ; Check busy flag (D7=0) ; Display OFF instruction ; Check busy flag (D7=0) ; Clear Display Instruction ; Check busy flag (D7=0) D7 1 Send Clear Display to IR D7 1 4-Apr-20
  • 20. Initialization Flowchart … Send Entry Mode to IR D7 1 Send Display ON to IR ; ;Send Entry Mode Instruction ; Check busy flag (D7=0) ; Display ON instruction ; Check busy flag (D7=0) ; Initialization Done ; Send Display RAM Address ; and data D7 1 Initialization is Complete Display is Ready 4-Apr-20
  • 21. Check Busy Flag OR Delay D7 1 Send Instruction to IR ;Before sending instruction / Command you can check Busy Flag Status (D7=0) Send Instruction to IR 4-Apr-20 ;Before sending instruction / Command you can give delay of 5 msec OR Delay of 5 msec
  • 22. Initialization of LCD (4 bit) 4-Apr-20
  • 23. LCD Program #1  Interface 2X16 LCD with 8051.Use 8 bit data length and write program to display “Y” in first line. Use P2 for data pins and P0 for control pins P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 P0.5 P0.6 P0.7 8051 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) + 5V + 5V 1K IR DR LCD 4-Apr-20
  • 24. LCD instructions Setting 1. Function Set D7 0 0 1 DL N F X X D6 D5 D4 D3 D2 D1 D0 DL = 1 N = 1 F = 0 ; data is sent or received in 8 bit length (D7 – D0). ; 2 line display ; 5 x 7 dots Function Set = 38H 0 0 1 1 1 0 0 0 4-Apr-20
  • 25. LCD instructions Setting 2. Display ON/OFF Control D7 D6 D5 D0 D1 D2 D3 D4 0 0 0 0 1 D C B D = 1 ;display is ON C = 1 ;cursor is displayed B = 1 ;Cursor blink Display ON Control = 0FH 3. Clear Display D7 0 0 0 0 0 0 0 1 D0 D1 D2 D3 D4 D5 D6 = 01H 0 0 0 0 1 1 1 1 Display OFF Control = 08H 0 0 0 0 1 0 0 0 4-Apr-20
  • 26. LCD instructions Setting 4. Entry Mode Set D7 0 0 0 0 0 1 I/D S D6 D5 D4 D3 D2 D1 D0 I/D = 1 ;Increments the DD RAM address by 1 when a character code is ;written or read from the DD RAM. ;The cursor moves to the right when incremented by +1 S = 0 ; No display shift Entry Mode Set = 06H 0 0 0 0 0 1 1 0 4-Apr-20
  • 27. LCD instructions Setting 4-Apr-20 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF 5. DD RAM Address DD RAM Addr ess Y LCD displa y e.g. To display characters in the first line, first position Set DD RAM address = 1000 0000 = 80H
  • 28. Flowchart Send 38H to IR ; Initialize LCD ; Send Function Set ; instruction 3 times ; wait for 5 msec ;Send Function Set instruction ; wait for 5 msec Wait for more than 4.1 msec Send 38H to IR Send 38H to IR ;Send Function Set Instruction ; Read & Check Busy Flag Wait for 100 usec D7 1 4-Apr-20
  • 29. Flowchart … Send 38H to IR D7 1 Send 08H to IR ; ;Send Function Set Instruction ; Check busy flag (D7=0) ; Display OFF instruction ; Check busy flag (D7=0) ; Clear Display Instruction ; Check busy flag (D7=0) D7 1 Send 01H to IR D7 1 4-Apr-20
  • 30. Flowchart … Send 06 H to IR D7 1 Send 0FH to IR ; ;Send Entry Mode Instruction ; Check busy flag (D7=0) ; Display ON instruction ; Check busy flag (D7=0) ; Initialization Done ; Send Display RAM Address ; and data D7 1 Initialization is Complete Display is Ready 4-Apr-20
  • 31. Flowchart… D7 ; Check busy flag (D7=0) 1 Send 80H to IR ; DD RAM Address : First Line, first position D7 ; Check busy flag (D7=0) 1 Send „Y” to DR ; ASCII CODE OF „Y‟ STOP 4-Apr-20
  • 32. Program #1 4-Apr-20 MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms ACALL CHK_BUSY MOV A, #38H ACALL COMM ACALL CHK_BUSY MOV A, #08H ACALL COMM ACALL CHK_BUSY MOV A, #01H ACALL COMM ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Check Busy Flag (D7 =0) then send ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Display OFF (0000 1 D C B) ; Clear Display
  • 33. Program #1 … 4-Apr-20 ACALL CHK_BUSY MOV A, #06H ACALL COMM ACALL CHK_BUSY MOV A, #0FH ACALL COMM ACALL CHK_BUSY MOV A, #80H ACALL COMM ACALL CHK_BUSY MOV A, #’Y’ ACALL DISP L1: SJMP L1 ; Entry mode: increment (0000 01 I/D S) ; Display ON (0000 1 D C B), CURSOR BLINK ; DD RAM Address (First Line, first position) ; ASCII CODE OF „Y‟ ; Subroutine to send data to DR ; Terminate Program
  • 34. Sub Programs #1 4-Apr-20 ; Subroutine to check Busy Flag CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction Register) SETB P0.6 ; RW=1, READ IR MOV A, P2 ; Read Data from IR (D7=Busy Flag) (D7=1, Busy) BUSY: JB ACC.7, BUSY RET ; Check Busy Flag status ; Busy Flag = 0 ; Subroutine to send data to IR (Instruction Register) ; EN=0 ; RS= 0, Register select (IR) ; RW=0, WRITE ; Send Data to IR ; EN=1 COMM: CLR P0.5 CLR P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0
  • 35. Sub Programs #1… 4-Apr-20 ; Subroutine to send data to DR (Data Register) DISP: ; EN=0 ; RS= 1, Register select (DR) ; RW=0, WRITE ; Send Data to DR ; EN=1 CLR P0.5 SETB P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0 ; Subroutine for Delay of 5 msec delay_5ms: MOV R0, #0AH L2: MOV R1, #0FEH L3: DJNZ R1, L3 DJNZ R0, L2 RET ; N = 10 ; N = 254 ; Decrement R1& JNZ ; Decrement R0& JNZ
  • 36. LCD Program #2  Interface 2X16 LCD with 8051.Use 8 bit data length and write program to display “HELLO” in first line. Use P2 for data pins and P0 for control pins P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 P0.5 P0.6 P0.7 8051 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) + 5V + 5V 1K IR DR LCD 4-Apr-20
  • 37. LCD instructions Setting 4-Apr-20 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF DD RAM Address DD RAM Addr ess H E L L O LCD displa y e.g. To display characters in the first line, first position Set DD RAM address = 1000 0000 = 80H
  • 38. Flowchart Send 38H to IR ; Initialize LCD ; Send Function Set ; instruction 3 times ; wait for 5 msec ;Send Function Set instruction ; wait for 5 msec Wait for more than 4.1 msec Send 38H to IR Send 38H to IR ;Send Function Set Instruction ; Read & Check Busy Flag Wait for 100 usec D7 1 4-Apr-20
  • 39. Flowchart … Send 38H to IR D7 1 Send 08H to IR ; ;Send Function Set Instruction ; Check busy flag (D7=0) ; Display OFF instruction ; Check busy flag (D7=0) ; Clear Display Instruction ; Check busy flag (D7=0) D7 1 Send 01H to IR D7 1 4-Apr-20
  • 40. Flowchart … Send 06 H to IR D7 1 Send 0FH to IR ; ;Send Entry Mode Instruction ; Check busy flag (D7=0) ; Display ON instruction ; Check busy flag (D7=0) ; Initialization Done ; Send Display RAM Address ; and data D7 1 Initialization is Complete Display is Ready 4-Apr-20
  • 41. Flowchart… D7 ; Check busy flag (D7=0) 1 Send 80H to IR ; DD RAM Address : First Line, first position D7 ; Check busy flag (D7=0) 1 Send „H” to DR ; ASCII CODE OF „H‟ Send „E” to DR ; ASCII CODE OF „E‟ 4-Apr-20
  • 42. Flowchart… Send „L” to DR ; ASCII CODE OF „L‟ Send „O” to DR ; ASCII CODE OF „O‟ Send „L” to DR ; ASCII CODE OF „L‟ STOP 4-Apr-20
  • 43. Program #2 4-Apr-20 MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms ACALL CHK_BUSY MOV A, #38H ACALL COMM ACALL CHK_BUSY MOV A, #08H ACALL COMM ACALL CHK_BUSY MOV A, #01H ACALL COMM ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Check Busy Flag (D7 =0) then send ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Display OFF (0000 1 D C B) ; Clear Display
  • 44. Program #2 4-Apr-20 ACALL CHK_BUSY MOV A, #06H ACALL COMM ACALL CHK_BUSY MOV A, #0FH ACALL COMM ACALL CHK_BUSY MOV A, #80H ACALL COMM ; Entry mode: increment (0000 01 I/D S) ; Display ON (0000 1 D C B), CURSOR BLINK ; DD RAM Address (First Line, first position) ACALL CHK_BUSY MOV A, #’H’ ACALL DISP MOV A, #’E’ ACALL DISP MOV A, #’L’ ACALL DISP MOV A, #’L’ ACALL DISP MOV A, #’O‟ ACALL DISP L1: SJMP L1 ; ASCII CODE OF „H‟ ; Subroutine to send data to DR ; ASCII CODE OF „E‟ ; Subroutine to send data to DR ; ASCII CODE OF „L‟ ; Subroutine to send data to DR ; ASCII CODE OF „L‟ ; Subroutine to send data to DR ; ASCII CODE OF „O‟
  • 45. Sub Programs #2 4-Apr-20 ; Subroutine to check Busy Flag CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction Register) SETB P0.6 ; RW=1, READ IR MOV A, P2 ; Read Data from IR (D7=Busy Flag) (D7=1, Busy) BUSY: JB ACC.7, BUSY RET ; Check Busy Flag status ; Busy Flag = 0 ; Subroutine to send data to IR (Instruction Register) ; EN=0 ; RS= 0, Register select (IR) ; RW=0, WRITE ; Send Data to IR ; EN=1 COMM: CLR P0.5 CLR P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0
  • 46. Sub Programs #2 4-Apr-20 ; Subroutine to send data to DR (Data Register) DISP: ; EN=0 ; RS= 1, Register select (DR) ; RW=0, WRITE ; Send Data to DR ; EN=1 CLR P0.5 SETB P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0 ; Subroutine for Delay of 5 msec delay_5ms: MOV R0, #0AH L2: MOV R1, #0FEH L3: DJNZ R1, L3 DJNZ R0, L2 RET ; N = 10 ; N = 254 ; Decrement R1& JNZ ; Decrement R0& JNZ
  • 47. LCD Program #3  Interface 2X16 LCD with 8051.Use 8 bit data length and write program to display “WELCOME” in first line. Use P2 for data pins and P0 for control pins P2.7 P2.6 P2.5 P2.4 P2.3 P2.2 P2.1 P2.0 P0.5 P0.6 P0.7 8051 15(BL) 14(D7) 13(D6) 12(D5) 11(D4) 10(D3) 9(D2) 8(D1) 7(D0) 6(EN) 5(R/W) 4(RS) 3(CONT) 2(VCC) 1(GND) + 5V + 5V 1K IR DR LCD 4-Apr-20
  • 48. LCD display 4-Apr-20 80 81 82 83 84 85 86 87 88 89 8A 8B 8C 8D 8E 8F C0 C1 C2 C3 C4 C5 C6 C7 C8 C9 CA CB CC CD CE CF  DD RAM Address DD RAM Addr ess W E L C O M E LCD displa y e.g. To display characters in the first line, first position Set DD RAM address = 1000 0000 = 80H
  • 49. LCD Program #3 W E L C O M E 0200H 0201H 0202H 0203H 0204H 0205H 0206H 00 R5 0200  ASCII codes of characters are transferred from program memory to Display RAM A DPTR W E L C O M E Display RAM 80H 81H 82H 83H 84H 85H 86H Program Memory Instructions 4-Apr-20 MOV A, R5 MOVC A, @ A + DPTR ACALL DISP INC R5
  • 50. LCD Program #3 …  Data Transfer Logic ; Initialise Base Address, ; Index, Counter ; Transfer index to ACC ; Use MOVC to read data ; Send data to Display RAM ; Increment index for nest Char ;Decrement the Counter and ;repeat till Counter is 0 DPTR = 0200H Base address R5 = 00 index, R6 = 7 counter, MOV A, R5 MOVC A, @A + DPTR Send Data of A to DR INC R5 DEC R6 & Repeat if R6 not 0 4-Apr-20
  • 51. Program #3 4-Apr-20 MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms MOV A, #38H ACALL COMM ACALL delay_5ms ACALL CHK_BUSY MOV A, #38H ACALL COMM ACALL CHK_BUSY MOV A, #08H ACALL COMM ACALL CHK_BUSY MOV A, #01H ACALL COMM ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Check Busy Flag (D7 =0) then send ; Function Set : 0011 NFXX, N=1: 2Line, F=0: 5x7 font ; Display OFF (0000 1 D C B) ; Clear Display
  • 52. Program #3 4-Apr-20 ACALL CHK_BUSY MOV DPTR, #0200H ; Base address of Look up table MOV R5, #00H ; Index first element of message string MOV R6, #07H ; R6 is counter for 7 characters to display L4: MOV A, R5 ; Index MOVC A, @A+DPTR ; Get ASCII code of character in ACC ACALL DISP ; Subroutine to send data to DR INC R5 ; Increment Index DJNZ R6, L4 ; Decrement Counter L5: SJMP L5 ; Terminate the Program ORG 0200H DB „WELCOME‟ ACALL CHK_BUSY MOV A, #06H ACALL COMM ACALL CHK_BUSY MOV A, #0FH ACALL COMM ACALL CHK_BUSY MOV A, #80H ACALL COMM ; Entry mode: increment (0000 01 I/D S) ; Display ON (0000 1 D C B), CURSOR BLINK ; DD RAM Address (First Line, first position)
  • 53. Sub Programs #3 4-Apr-20 ; Subroutine to check Busy Flag CHK_BUSY: CLR P0.7 ; RS= 0, Register select (Instruction Register) SETB P0.6 ; RW=1, READ IR MOV A, P2 ; Read Data from IR (D7=Busy Flag) (D7=1, Busy) BUSY: JB ACC.7, BUSY RET ; Check Busy Flag status ; Busy Flag = 0 ; Subroutine to send data to IR (Instruction Register) ; EN=0 ; RS= 0, Register select (IR) ; RW=0, WRITE ; Send Data to IR ; EN=1 COMM: CLR P0.5 CLR P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0
  • 54. Sub Programs #3 4-Apr-20 ptkarule@ycce.edu ; Subroutine to send data to DR (Data Register) DISP: ; EN=0 ; RS= 1, Register select (DR) ; RW=0, WRITE ; Send Data to DR ; EN=1 CLR P0.5 SETB P0.7 CLR P0.6 MOV P2, A SETB P0.5 NOP NOP NOP CLR P0.5 RET ; EN=0 ; Subroutine for Delay of 5 msec delay_5ms: MOV R0, #0AH L2: MOV R1, #0FEH L3: DJNZ R1, L3 DJNZ R0, L2 RET ; N = 10 ; N = 254 ; Decrement R1& JNZ ; Decrement R0& JNZ