Liquid crystal display Interfacing With 8051 in 4 Bit Mode
-
Upload
mani-sekar -
Category
Documents
-
view
218 -
download
0
Transcript of Liquid crystal display Interfacing With 8051 in 4 Bit Mode
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
1/10
LCD Interfacing with 8051 in 4 bit mode : assembly tutorial
Hello friends, in this tutorial we are going to interface LCD with 8051 microcontroller but in 4
bit mode. we already interfaced LCD with 8051 in 8 bit and also done scrolling of tetin !re"ious tutorials.
LCD interfacing with 8051 in assembly in 8 bit mode
#croll tet on a 1$% LCD with 8051 microcontroller
if you already &now how to interface LCD with microcontroller in 8 bit mode then it isnot difficult to interface LCD in 4 bit mode. but if you don't &now how to interface LCD with8051 microcontroller in 8 bit mode than read these !oints.
(irst we initiali)e LCD by sending different command
*o send command we ma&e +#0-low and !ut command on D/*/ !ins of LCDD02
D3
http://www.tentuts.com/2012/12/lcd-interfacing-with-8051-in-4-bit-mode.htmlhttp://www.tentuts.com/2012/01/lcd-interfacing-with-8051-in-assembly.htmlhttp://www.tentuts.com/2012/01/tutorial-for-scroll-text-on-16x2-lcd.htmlhttp://www.tentuts.com/2012/01/lcd-interfacing-with-8051-in-assembly.htmlhttp://www.tentuts.com/2012/01/tutorial-for-scroll-text-on-16x2-lcd.htmlhttp://www.tentuts.com/2012/12/lcd-interfacing-with-8051-in-4-bit-mode.html -
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
2/10
*hen ma&e 6 1-high and after some delay 6 0-low. it ma&e a high to low !ulse
on 6 of LCD
Do same thing to send data but this time +# 1-high
this is called LCD interfacing in 8 bit mode
ut in 4 bit interfacing mode that we only use 4 data lines -D42D3 of LCD. /s we are goingto use only 4 data lines so we need to send data in grou! of 4 bits called nibble. *he Higher
nibble is send first and then lower nibble is send. 7n this !rogram i use two memory location to
store my u!!er and lower nibble after se!arating a 8 bit data.
This is how i connect LCD and other ariables
U equ 31H ;memory location to hold upper nibble L equ 32H ;memory location to hold lower nibble
Port equ P1 ;data port to connect LCD RS equ P2! ;RS pin connection R" equ P21 ;R" pin connection #$ equ P22 ;#$ pin connection
;connection o% Port ;Port1&Port3 'not u(ed) ;Port* + D,* ;Port- + D,- ;Port. + D,. ;Port/ + D,/
!ow i send Data and Command
/s you can see from connection of LCD and microcontroller that i can send data to LCD in the
u!!er nibble of the !ort only because lower nibble is not connected. so if i need to send 0%H*wo then i ha"e to send it as %0h. by doing this LCD read only u!!er nibble of !ort that is %.
/nd if i need to send %8h then i send first %0h and then 80h.u!!er nibble first and lower nibble
second.
!ow to "rea# 8 bit Data
4 bit LCD interfacing mode reuire that we first brea& 8 bit data in to 4 bit data and then send itto LCD.
Let we ha"e %8h in accumulator register and we are going to send it to LCD. #o we need tobrea& it. 9e can brea& it as %0h higher nibble and 80h lower nibble.
7f i !erform /6D o!eration of %8h with (0h then it become %0H u!!er nibble and if i swa!
nibbles of %8h become 8%h and then do same /6Ding then i got 80H lower nibble.9e can write a routine to !erform se!aration because it needed when we send command and data
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
3/10
to LCD. lets call it $e%arator.i use two memory location to store to u!!er: nibble and lower
nibbleL. it will ma&e the !rogram sim!le and better understandable.0000000000000000000000000000000000000000000000000000
(eparator 4 U56 ;(a7e 6 at temp location U 6$L U58!9!H ;ma(: it with !9h '2h < 9!h + 2!h)
S"6P 6 ;(wap nibble '2h += 2H) 6$L 658!9!H ;ma(: it with !%h '2h < %!h + !h) 4 L56 ;(a7e it at temp location L R#> ;return 00000000000000000000000000000000000000000000000000000
&oe Data'Command to LCD
i write many routine so the code become sim!ler because long code is easy to understand thanshorter and com!act one. but you can !ut all in single routine.
Let ma&e a routine which !ut data;command on , #$ ;ma:e #$ hi@ht 6C6LL D#L6A ;call a (hort delay routine CLR #$ ;clear #$ 6C6LL D#L6A ;(hort delay R#> ;return 00000000000000000000000000000000000000000000000000000
$end Command to LCD
6ow i need to send command to LCD. if i set rs0 and send data then LCD consider it ascommand. let call it lcd(cmd 00000000000000000000000000000000000000000000000000000 lcd?cmd CLR RS ;clear r(5 @oin@ to (end command 6C6LL (eparator ;(eparate the command and (a7e to U and L 4 65 U ;copy U to 6 6C6LL mo7e?to?port ;mo7e content o% a to port
4 65 L ;copy L to 6 6C6LL mo7e?to?port ;mo7e content o% a to port
R#> ;return 00000000000000000000000000000000000000000000000000000
now you can send command easily to LCD. you only need !ut command in / and call lcd=cmd.
$end Data to LCD
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
4/10
+outine to send data to LCD remain same as to send command. the only thing change that this
time +# will be High.00000000000000000000000000000000000000000000000000000
lcd?data S#>, RS ;RS+15 @oin@ to (end D6>6 6C6LL (eparator ;(eparate the data and (a7e to U < L
4 65 U ;copy U to 6 6C6LL mo7e?to?port ;(end it to LCD 4 65 L ;copy L to 6 6C6LL mo7e?to?port ;(end it to LCD R#> ;return 00000000000000000000000000000000000000000000000000000
The Delay
Delay ha"e a great role in LCD interfacing with 8051 microcontroller. ecause !rocessing s!eed
of LCD and 8051 is not same. /nd LCD need some time to !rocess the command, and 8051 ha"e
to wait. if the delay is not !ro!er and you gi"e command to LCD then LCD will not recei"e itbecause it is busy in doing some thing else. let ma&e a short delay routine.
00000000000000000000000000000000000000000000000000000 delay 4 R!5 81!H L2 4 R158!9H L1 DB$ R15 L1 DB$ R!5 L2 R#> 00000000000000000000000000000000000000000000000000000
you can change the "alue of delay i ta&e it randomly. chec& datasheet for !recise delay.
)eady to launch the )oc#et
>? we ha"e all the routine and function. now we only need to initiali)e the LCD by sending
some command and then we can send the data bytes.Here is
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
5/10
Initiali*ationefore sending any thing to LCD first i need to tell LCD that i am going to interface in 4 bitmode. to do this i first send %0h on the !ort and ma&e switching of 6. all commands are2
1. #end %0h to set 4 bit mode
%. #end %8h to set 4 bit 7nterface,% Line LCD, and 53 (ont set,
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
6/10
@. #end 0ch to set Dis!lay >6, Cursor >(( and lin& >6
4. #end 0$h to set Cursor
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
7/10
CLR R" 6C6LL init
4 65 8F>F ;S#$D G>#$>U>SC *,>G6C6LL lcd?data ;in %ir(t line o% LCD
4 65 8F#F 6C6LL lcd?data 4 65 8F$F 6C6LL lcd?data 4 65 8F>F 6C6LL lcd?data 4 65 8FUF 6C6LL lcd?data 4 65 8F>F 6C6LL lcd?data 4 65 8FSF 6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8FCF
6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8F F 6C6LL lcd?data 4 65 8F*F 6C6LL lcd?data 4 65 8F,F 6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8F>F 6C6LL lcd?data
4 65 8!c!H ;(witch to 2nd line o% LCD 6C6LL lcd?cmd
4 65 8FF ;S#$D GD# US$E 2 PR>G6C6LL lcd?data ;in S#C$D line o% LCD
4 65 8FF 6C6LL lcd?data 4 65 8FDF 6C6LL lcd?data 4 65 8F#F 6C6LL lcd?data
4 65 8F F 6C6LL lcd?data 4 65 8FUF 6C6LL lcd?data 4 65 8FSF 6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8F$F 6C6LL lcd?data
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
8/10
4 65 8FEF 6C6LL lcd?data 4 65 8F F 6C6LL lcd?data 4 65 8F2F 6C6LL lcd?data 4 65 8FPF 6C6LL lcd?data 4 65 8FF 6C6LL lcd?data 4 65 8FRF 6C6LL lcd?data 4 65 8F>F 6C6LL lcd?data
SBP ;$9$># L$E LP
;00000000000000000000000000000Separator;00000000000000000000000000000000000000
(eparator 4 U56 ;(a7e 6 at temp location U 6$L U58!9!H ;ma(: it with !9h '2h < 9!h + 2!h)
S"6P 6 ;(wap nibble '2h += 2H) 6$L 658!9!H ;ma(: it with !%h '2h < %!h + !h) 4 L56 ;(a7e it at temp location L R#> ;return
;00000000000000000000000000o7e >o Port;00000000000000000000000000000000000000
mo7e?to?Port
4 port56 ;put content o% 6 to port S#>, #$ ;ma:e #$ hi@h 6C6LL D#L6A ;call a (hort delay routine CLR #$ ;clear #$ 6C6LL D#L6A ;(hort delay R#> ;return
;00000000000000000000000000LCD command;00000000000000000000000000000000000000
lcd?cmd CLR RS ;clear r(5 @oin@ to (end command 6C6LL (eparator ;(eparate the command and (a7e to U and L 4 65 U ;copy U to 6 6C6LL mo7e?to?port ;mo7e content o% a to port
4 65 L ;copy L to 6 6C6LL mo7e?to?port ;mo7e content o% a to port R#> ;return
;000000000000000000000000000000LCD data;00000000000000000000000000000000000000
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
9/10
lcd?data S#>, RS ;RS+15 @oin@ to (end D6>6 6C6LL (eparator ;(eparate the data and (a7e to U < L 4 65 U ;copy U to 6 6C6LL mo7e?to?port ;(end it to LCD 4 65 L ;copy L to 6 6C6LL mo7e?to?port ;(end it to LCD R#> ;return
;0000000000000000000000000nitiliIation;00000000000000000000000000000000000000
init 6C6LL delay ;(ome delay to lcd a%ter power on 6C6LL delay
4 port5 82!h ;(end 2!h to lcd to (et * bit mode CLR RS ;a%ter that we can u(e lcd?cmd S#>, #$ ;ma:e #$ (witchin@ 6C6LL delay
CLR #$
4 65 82H 6C6LL lcd?cmd 4 65 8!CH 6C6LL lcd?cmd 4 65 8!.H 6C6LL lcd?cmd 4 65 8!1H 6C6LL lcd?cmd R#>
;000000000000000000000000000000000Delay;00000000000000000000000000000000000000
delay 4 R!5 81!H L2 4 R158!9H L1 DB$ R15 L1 DB$ R!5 L2 R#>
;000000000000000000000000000000000000000
end
Circuit diagram of LCD interfacing with 8051 in 4 bit mode
-
7/25/2019 Liquid crystal display Interfacing With 8051 in 4 Bit Mode
10/10
/L+*B here i use % different !ort of 8051