Interfacing keypad and LCD with 8051

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Hello,

i'm trying to send data to LCD with a Keypad (3x4) like a phone keypad.
so i know how to send data one by one, like when i click 1 it displays 1 in the LCD and so on.
This is ok for me.

But now i want to type a word for example "ABC" then when i will click on "#" button it will send the word "ABC" to the LCD and only after i clicked the "#" button not one by one letter.

how do i have to modify my asm code.

The LCD is connected to P2.

here is the code :
KEYPAD:
Rich (BB code):
mov p1,#0ffh  ; MAKE P3 as input for keypad
lcall Line0
lcall delay

mov p1,#0ffh
lcall Line1
lcall delay

mov p1,#0ffh
lcall Line2
lcall delay
Line0:
clr p1.0
jb p1.1,L1
lcall Col1 
jnb p1.1,$
ret

L1:
jb p1.4,L2
lcall Col2  
jnb p1.4,$
ret

L2:
jb p1.5,L3
lcall Col3  
jnb p1.5,$
ret

L3:
jb p1.6,L4
lcall Col4  
jnb p1.6,$
l4:ret
;---------------
Col1:
lcall lcdtrans 
mov a,#'A'; display 1
mov p2,a
lcall LCDdata 
ret
Col2:
lcall lcdtrans
mov a,#'D'; display 4	 
mov p2,a
lcall LCDdata 
ret
Col3:
lcall lcdtrans
mov a,#'G'; display 7	
mov p2,a
lcall LCDdata
ret
Col4:
lcall lcdtrans
mov a,#'J'; dipslay * 
mov p2,a
lcall LCDdata 
ret

Line1:
clr p1.1
jb p1.3,L11
lcall Col11
lcall lcdtrans  
jnb p1.3,$
ret

L11:
jb p1.4,L22
lcall Col22
lcall lcdtrans  
jnb p1.4,$
ret
L22:
jb p1.5,L33
lcall Col33
lcall lcdtrans  
jnb p1.5,$
ret

L33:
jb p1.6,L44
lcall Col44 
lcall lcdtrans 
jnb p1.6,$
L44:ret
;----------------
Col11: 
lcall lcdtrans
mov a,#'B'; display 2
mov p2,a 
lcall LCDdata 
ret
Col22:
lcall lcdtrans
mov a,#'E'; display 5	 
mov p2,a
lcall LCDdata
ret
Col33:
lcall lcdtrans
mov a,#'H'; display 8	
mov p2,a
lcall LCDdata
ret
Col44:
lcall lcdtrans
mov a,#'K'; dipslay 0 
mov p2,a
lcall LCDdata
ret
;---------------
Line2:
clr p1.2
jb p1.3,LA
lcall ColA 
lcall lcdtrans 
jnb p1.3,$
ret

LA:
jb p1.4,LB
lcall ColB 
lcall lcdtrans 
jnb p1.4,$
ret
LB:
jb p1.5,LC
lcall ColC 
lcall lcdtrans 
jnb p1.5,$
ret
LC:
jb p1.6,LD
lcall ColD 
lcall lcdtrans 
jnb p1.6,$
LD:ret
;-----------------
ColA: 
lcall lcdtrans
mov a,#'C'; display 3
mov p2,a 
lcall LCDdata 
ret
ColB:
lcall lcdtrans
mov a,#'F'; display 6	 
mov p2,a
lcall LCDdata
ret
ColC:
lcall lcdtrans
mov a,#'I'; display 9	
mov p2,a
lcall LCDdata
ret
ColD:
lcall lcdtrans
mov a,#'L'; dipslay # 
mov p2,a
lcall LCDdata 
ret
Thank you
PS: there is one problem with my code, the letter A is never displayed, i tried to understand, for me the code is good maybe there is a problem with xtal frequencey or i don't know what.
 

MrChips

Joined Oct 2, 2009
35,115
There are some essential steps required to design a successful program, even before you start writing code. This is called Top-Down Design.

1) Define and identify the problem.
2) Create an algorithm that solves the problem.
3) Write out the steps of the algorithm in plain language.
4) Draw a flow chart to show the flow of the algorithm.

Only after those steps are taken do you begin to write code.
Learn to comment all your code with appropriate and meaningful comments.
 

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Hello Ms Chips,
thank you for your advice.
Here i'm doing some exercise by myself to learn asm.
I'm trying to understand how the keypad have to be coded to send a word to LCd using 8051 µc.
So first, i did the first example with a keypad and a 7 segment led with 8051 and it was working fine.
Second i tried to connect two 8051 in serial communication and use interrupt function to send data to LCD through a Keypad between the two 8051, and it was working fine, each time a pressed a button in the keypad that data is displayed in the LCD nad i can do it from one 8051 to another 8051 and vice et versa.

But now i tried to send a word to the LCD with the keypad. so i tried many times to modify the above code but it did not work.

Yes for the algorythm, i used many papers and i didn't find any solution.

So can you give me clue not the solution, but only a guidance.
do i have to use DPTR function or anything else?

i want to do it in asm, i did not start the Embedded C yet.
Do u want the above code fully commented?


Thank you for your support.
 
Top