Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

LCD interfacing with the 8051 microntroller...

Status
Not open for further replies.

microcontroller123

Junior Member level 1
Junior Member level 1
Joined
Feb 15, 2011
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,472
hi.. i have interfaced the 4x3 keypad and 16x2 LCD with 8051 micro-controller..
its working properly but the problem is that i need the data to be written on the LCD digit by digit... but in my case i am getting over write on the previous digit by the new one.. here is my code.. kindly help me its the part of my FYP..
Thanks

Code:
org 0h

;keypad -->  port1
;LCD --> port2
;RS -->	p0.0
;R/W --> p0.1
;E --> p0.2
main:
mov r5,#2d
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0

mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1

mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2

mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3

ljmp again1


row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find


find:
rrc a
jnc match
inc dptr
sjmp find

match:
clr a
movc a,@a+dptr
mov r2,a
/// here the pointer stuck on "acall display_start" and dont go for djnz
acall display_start

//using djnz to take input twice and display two digits on the LCD
// r5 is loaded with the value two as mentioned above.. mov r5,#2d
djnz r5,again





delay:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret





display_start:
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
mov a,r2
acall display
ret

command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay1
clr p0.2
ret

ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay1
setb p0.2
jb p2.7,back
ret

delay1: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret




org 300h

code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h




end





but its not working properly and the LCD isn't showing any data due to the presence of the instruction djnz r5,again
 
Last edited by a moderator:

may be this file can help you
 

Attachments

  • mcs51 to lcd.pdf
    2.1 MB · Views: 232

i have read it already thoroughly.. its the book of mazidi.. but unfortunately it cant help me to solve my mistake.. there is a slight mistake in code.. and i cant understand it properly.. thats why.. if you dun mind kindly review my code ....
thanks
 

seen this too... its the same code as given in mazidi.. no help ful.. even my code for the keypad is much better than this.. cz i am using single port of 8051 rather than two ports
 

On reading your post and having a quick look at your code,
It seems that each and every time as a key is find pressed it goes to
"display_start:"
Instead it should be called only once in the program at the beginning and you should write a code that only displays the data

Hope you understand
 

i can understand what you have said that every time i call display_start.. but how can i do to display three characters without overwritten? please give me a hint ... cz i have been stuck in this code for three days..
thanks
 

the format of the code is wrong. before using a device under stand the basics first. start your project with step by step process. first start with lcd, lcd has to be initialized before it has to be used. display the project name and then proceed to scan the keypad. either use pull ups in p0 or use p3 for RS, RW, EN.

all the best
 

the format of the code is wrong. before using a device under stand the basics first. start your project with step by step process. first start with lcd, lcd has to be initialized before it has to be used. display the project name and then proceed to scan the keypad. either use pull ups in p0 or use p3 for RS, RW, EN.

all the best


i have done it already.. first using the lcd and then keypad... after that i merged them into one code.. but still i am facing problem..
in another code i have tried

Code:
org 0h

;keypad -->  port1
;LCD --> port2
;RS -->	p0.0
;R/W --> p0.1
;E --> p0.2

mov a,#38h
acall command  // here the code stuck when i debug the code
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0

mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1

mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2

mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3

ljmp again1


row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find


find:
rrc a
jnc match
inc dptr
sjmp find

match:
clr a
movc a,@a+dptr
mov r2,a

acall on_lcd
ljmp again




delay:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret




/*
display_start:
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command
ret
*/
on_lcd:
mov a,r2
acall display
ret

command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret
display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay1
clr p0.2
ret

ready: 
setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay1
setb p0.2
jb p2.7,back
ret

delay1: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret




org 300h

code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h




end

in this code i have initialized the LCD first and then i tried to display the character on the LCD but still the same problem...kindly help me
 
Last edited by a moderator:

Code:
Rs 			equ 	p1.2
rw 			equ 	p1.1
en 			equ 	p1.0
busy 		bit 	p0.7
dat			equ	p0



org 0h
jmp main


org 30h
main:
	
	Call linit
	mov dptr,#mes1
	call messdisp

        mov a,#'o'
        call datawrt
        
        mov a,#'k'
        call datawrt
	jmp $
linit:	
	Clr rw
	mov a,#38h      ;lcd 2 lines
	call comnwrt
	
        call clears
	call sline
        
        mov a,#0ch 	;display on cursor on
	call comnwrt
	
        mov a,#6h 	;shift cursor right
	call comnwrt
fline:	
	Mov a,#80h      ;send first line address
        call comnwrt
ret

sline:
	Mov a,#0c0h      ;send first line address
        call comnwrt
ret
clears:
	Mov a,#01h 	;clear display
	call comnwrt
ret
	
comnwrt:
	Call ready
       	mov  dat,a
       	clr  rs
       	setb en
       	clr  en
ret

datawrt:
	Call ready
       	mov  dat,a
       	setb rs
       	setb en
       	clr  en
ret
       
ready:
	Setb busy
	setb rw
	clr rs
c1:
	Clr en
	nop
	nop
	setb en
	jb busy,c1
	clr rw
ret

messdisp:
	D1:clr a
	movc a,@a+dptr
	cjne a,#0ffh,cont
ret
cont:
	Call datawrt
	inc dptr
sjmp d1

delay:
        Mov r7,#10d
	l2: Mov r6,#100d
l1:
	Call del
	djnz r6,l1
	djnz r7,l2
ret
 
del:
	Clr cprl2
	clr ct2
	mov tl2,#7ch
	mov th2,#0fch	
	setb tr2
	jnb tf2,$
	clr tr2
	clr tf2
ret;

mes1:	Db	"testing ",255
end

use this code for testing lcd
 
Last edited by a moderator:

thanks a lot...
another thing i want to clarify from you.... i am using two micro-controllers and want to set up a communication in between them using rf modules working on 433Mhz.. before that i have just tried to simulate my problem by just connecting the tx of first micro to the rx of second micro...
the results are:

t-r.JPG

transmitting code:
org 0h
//timer initialization
mov tmod,#20h
mov th1,#0fah
mov scon,#50h
setb tr1
clr ti
//***********
mov r5,#3
//LCD initialization
mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command

here1:
acall again
mov a,r2
acall send
acall display
djnz r5,here1

mov r5,#3
mov a,#0c6h
acall command

repeat:
acall again
mov a,r2
acall display
djnz r5,repeat
sjmp $


command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret

display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay
clr p0.2
ret

ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay
setb p0.2
jb p2.7,back
ret
//****************

//SEND
send:
mov sbuf,a
stay: jnb ti,stay
clr ti
ret
//***************

//KEYPAD routine
again:
mov p1,#00000111b
mov a,p1
anl a,#00000111b
cjne a,#00000111b,again
again1:
acall delay1
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check
sjmp again1
check:
mov a,p1
anl a,#00000111b
cjne a,#00000111b,check1
sjmp again1
check1:
mov p1,#11110111b
mov a,p1
anl a,#11110111b
cjne a,#11110111b,row0

mov p1,#11101111b
mov a,p1
anl a,#11101111b
cjne a,#11101111b,row1

mov p1,#11011111b
mov a,p1
anl a,#11011111b
cjne a,#11011111b,row2

mov p1,#10111111b
mov a,p1
anl a,#10111111b
cjne a,#10111111b,row3

ljmp again1


row0:
mov dptr,#code0
sjmp find
row1:
mov dptr,#code1
sjmp find
row2:
mov dptr,#code2
sjmp find
row3:
mov dptr,#code3
sjmp find


find:
rrc a
jnc match
inc dptr
sjmp find

match:
clr a
movc a,@a+dptr
mov r2,a

//LCD delay
delay: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret

//KEYPAD delay
delay1:
mov r0,#72
label:
mov r1,#255
label1:
djnz r1,label1
djnz r0,label
ret

org 300h

code0: db "1","2","3"
code1: db "4","5","6"
code2: db "7","8","9"
code3: db 2Ah,"0",23h

//************

end


receiving code
org 0h
mov tmod,#20h
mov th1,#0fah
mov scon,#50h
setb tr1
clr ri

mov r5,#3

mov a,#38h
acall command
mov a,#0eh
acall command
mov a,#01h
acall command
mov a,#06h
acall command
mov a,#86h
acall command

repeat:
acall recv
acall display
djnz r5,repeat

mov r5,#3
mov a,#0c6h
acall command


here1:
acall recv
acall display
djnz r5,here1

recv:
stay:jnb ri,stay
mov a,sbuf
clr ri
ret

command: acall ready
mov p2,a
clr p0.0
clr p0.1
setb p0.2
clr p0.2
ret

display: acall ready
mov p2,a
setb p0.0
clr p0.1
setb p0.2
acall delay
clr p0.2
ret

ready: setb p2.7
clr p0.0
setb p0.1
back: clr p0.2
acall delay
setb p0.2
jb p2.7,back
ret

delay: mov r3,#50
here:
mov r4,#255
here2:
djnz r4,here2
djnz r3,here
ret
end
 

i dun know why its not receiving the data on the second line.. kindly help me to resolve my issue.. thnx
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top