interfacing a 4*4 keypad is a really difficult way to take input on micro controller BUT there is a very easy method to interface 4*4 keypad which does not require anything but a single encoder MM74C922.
SCHEMATIC:
MM74C922:
Many of us don't know about this IC what actually is the function of this chip?
It is the CMOS based IC which is capable of encoding an array of SPST (single pole single throw) switches key bouncing can also be reduced by using capacitor on key bounce pin ..
this IC encode the 8 bit code into 4 bit and send it to micro controller.
CODE:
Most of our work is done by MM74C922 now we just have to check what binary is being generated by pressing the keys on keypad.
For Example :
- If we press '7' on keypad '0000' will occur on output port.
- If we press '4' on keypad '0001' will occur on output port.
If we press '1' on keypad '0010' will occur on output port.
now we know what the user want to write by checking the binary output.
If we want to write the number on LCD which is being pressed
SCHEMATIC:
CODE:
org 00H
jmp 30H
org 30H
;---WRITING COMMANDS ON LCD ----
mov A,#38h ;Use 2 lines and 5×7 matrix for LCD
acall com_wrt ; calling function to enter command on LCD
mov A,#0Fh ; LCD ON, Cursor ON, Cursor blinking ON
acall com_wrt ; calling function to enter command on LCD
mov A,#01h ; clearing the LCD
acall com_wrt ; calling function to enter command on LCD
mov A,#80h ; Force cursor to the beginning of 1st line
acall com_wrt ; calling function to enter command on LCD
;---CLEARING/SETTING PORTS/PINS----
mov P2,#00H ; clearing port 2 to eleminate garbage value
mov p1,#00H ; clearing port 2 to eleminate garbage value
setb P3.7 ; setting P3.7 to high (1) commanding MC to read when bit gets low (0)
;---START OF PROGRAM----
MAIN:
clr A ; clear garbage value from accumulator
call delay ; calling funtion for some delay
jb p3.7,main ; checking if there is any button pressed on hexpad if not jump to main
mov A,p0 ; copying data of pressed button in accumulator
call delay ; calling funtion for some delay
cjne a,#0000b,chk1 ; checking if button pressed has a binary of 0000
mov A,#'7' ; if yes send "7" on data port
call char_wrt ; calling function to display character on LCD
chk1:
cjne a,#0001b,chk2 ; checking if button pressed has a binary of 0001
mov A,#'4' ; if yes send "4" on data port
call char_wrt ; calling function to display character on LCD
chk2:
cjne a,#0010b,chk3 ; checking if button pressed has a binary of 0010
mov A,#'1' ; if yes send "1" on data port
call char_wrt ; calling function to display character on LCD
chk3:
cjne a,#0011b,chk4 ; checking if button pressed has a binary of 0011
jmp main
chk4:
cjne a,#0100b,chk5 ; checking if button pressed has a binary of 0100
mov A,#'8' ; if yes send "8" on data port
call char_wrt ; calling function to display character on LCD
chk5:
cjne a,#0101b,chk6 ; checking if button pressed has a binary of 0101
mov A,#'5' ; if yes send "5" on data port
call char_wrt ; calling function to display character on LCD
chk6:
cjne a,#0110b,chk7 ; checking if button pressed has a binary of 0110
mov A,#'2' ; if yes send "2" on data port
call char_wrt ; calling function to display character on LCD
chk7:
cjne a,#0111b,chk8 ; checking if button pressed has a binary of 0111
mov A,#'0' ; if yes send "0" on data port
call char_wrt ; calling function to display character on LCD
chk8:
cjne a,#1000b,chk9 ; checking if button pressed has a binary of 1000
mov A,#'9' ; if yes send "9" on data port
call char_wrt ; calling function to display character on LCD
chk9:
cjne a,#1001b,chk10 ; checking if button pressed has a binary of 1001
mov A,#'6' ; if yes send "6" on data port
call char_wrt ; calling function to display character on LCD
chk10:
cjne a,#1010b,chk11 ; checking if button pressed has a binary of 1010
mov A,#'3' ; if yes send "3" on data port
call char_wrt ; calling function to display character on LCD
chk11:
cjne a,#1011b,chk12 ; checking if button pressed has a binary of 1011
mov A,#'=' ; if yes send "=" on data port
call char_wrt ; calling function to display character on LCD
chk12:
cjne a,#1100b,chk13 ; checking if button pressed has a binary of 1100
mov A,#'/' ; if yes send "/" on data port
call char_wrt ; calling function to display character on LCD
chk13:
cjne a,#1101b,chk14 ; checking if button pressed has a binary of 1101
mov A,#'*' ; if yes send "*" on data port
call char_wrt ; calling function to display character on LCD
chk14:
cjne a,#1110b,chk15 ; checking if button pressed has a binary of 1110
mov A,#'-' ; if yes send "-" on data port
call char_wrt ; calling function to display character on LCD
chk15:
cjne a,#1111b,return_main ; checking if button pressed has a binary of 1111
mov A,#'+' ; if yes send "+" on data port
call char_wrt ; calling function to display character on LCD
return_main:
ljmp main ; long jump to "main"
;---CHARACTER DISPLAYING MODULE----
char_wrt:
acall delay ; calling some time delay
setb p3.0 ; setting bit register select high
clr p3.1 ; clearing bit to write data on LCD
mov p2,A ; moving character to data port
setb p3.2 ; setting bit enable for starting clock
nop ; time delay
nop ; time delay
clr p3.2 ; clearing bit enable for ending clock
ret
;---COMMAND DISPLAYING MODULE----
com_wrt:
acall delay ; calling some time delay
clr p3.0 ; setting bit register select high
clr p3.1 ; clearing bit to write data on LCD
mov p2,A ; moving character to data port
setb p3.2 ; setting bit enable for starting clock
nop ; time delay
nop ; time delay
clr p3.2 ; clearing bit enable for ending clock
ret
;---DELAY MODULE----
delay:
mov r6,#088h
loop:
djnz r5,$
djnz r6,loop
ret
end
No comments:
Post a Comment