Tuesday, May 31, 2016

8051 Program - 4 bit lcd code

;4-bit lcd code for 16x2 and 16x4 display (hd44780 compatable lcd)
;pin configuration
;P1.7 --------> DB7
;P1.6 --------> DB6
;P1.5 --------> DB5
;P1.4 --------> DB4
;P3.7 --------> EN
;P3.5 --------> RS
;P3.4 --------> RW
org 0000h
ljmp main
org 0030h
main: nop
en equ p3.7
rs equ p3.5
rw equ p3.4
dat equ p1
lcall lcd_int
again: lcall clear
lcall line1
mov dptr,#mydata
lcall loop
lcall line2
mov dptr,#mydat2
lcall loop
;lcall line3;(16x4)
;mov dptr,#mydat3;(16x4)
;lcall loop ;(16x4)
;lcall line4 ;(16x4)
;mov dptr,#mydat4 ;(16x4)
;lcall loop ;(16x4)
lcall line1
mov dptr,#mydat5
lcall loop
lcall line2
mov dptr,#mydat6
lcall loop
;lcall line3 ;(16x4)
;mov dptr,#mydat7 ;(16x4)
;lcall loop ;(16x4)
;lcall line4 ;(16x4)
;mov dptr,#mydat8 ;(16x4)
;lcall loop ;(16x4)
sjmp again
w_nib: push acc ;save a for low nibble
orl dat,#0f0h ;bits 4..7 <- 1="" td="">
orl a,#0fh ;don't affect bits 0-3
anl dat,a ;high nibble to display
setb en
clr en
pop acc ;prepare to send
swap a ;...second nibble
orl dat,#0f0h ; bits 4...7 <- 1="" td="">
orl a,#0fh ; don't affect bits 0...3
anl dat,a ;low nibble to display
setb en
clr en
ret
lcd_int: clr rs
clr rw
clr en
setb en
mov dat,#028h
clr en
lcall sdelay
mov a,#28h
lcall com
mov a,#0ch
lcall com
mov a,#06h
lcall com
lcall clear
mov a,#080h
lcall com
ret
clear: clr rs
mov a,#01h
lcall com
ret
dataw:setb rs
clr rw
lcall w_nib
lcall ldelay
ret
sdelay: mov r6,#1
here2:mov r7,#255
here:djnz r7,here
djnz r6,here2
ret
ldelay: mov r6,#100
her2: mov r7,#255
her:djnz r7,her
djnz r6,her2
ret
com: clr rs
clr rw
lcall w_nib
lcall sdelay
ret
line1:mov a,#002h
lcall com
ret
line2:mov a,#0c0h
lcall com
ret
line3:mov a,#090h
lcall com
ret
line4: mov a,#0d0h
lcall com
ret
loop:clr a
movc a,@a+dptr
jz go_b2
lcall dataw
lcall sdelay
inc dptr
sjmp loop
go_b2: ret
mydata: db " line1 ",0
mydat2: db " line2 ",0
mydat3: db " line3 ",0
mydat4: db " line4 ",0
mydat5: db " line5 ",0
mydat6: db " line6 ",0
mydat7:db " line7 ",0
mydat8: db " line8 ",0



Related topics:
8051 Program - 8 bit lcd code   |   8051 Program - running led   |   8051 Program - 32bit multiplication   |   8051 Program - memory subroutines   |   8051 Program - math subroutines   |   8051 Program - conversion subroutines

List of topics: 8051

No comments:

Post a Comment