mytutorialcafe.com Forum Index mytutorialcafe.com
Discussion All About Microcontroller and Computer Interfacing
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Reading key sequence from 4x4 keypad

 
Post new topic   Reply to topic    mytutorialcafe.com Forum Index -> Interfacing with Microcontroller
View previous topic :: View next topic  
Author Message
cak kalim



Joined: 05 May 2006
Posts: 5

PostPosted: Tue May 09, 2006 2:23 am    Post subject: Reading key sequence from 4x4 keypad Reply with quote

How to read 3 key sequence (example 4,5,6) from a keypad?
If the sequence is correct then the led on.

Have idea, pleasetell me.
Back to top
View user's profile Send private message
myturf
Site Admin


Joined: 01 Jan 1970
Posts: 10

PostPosted: Tue May 09, 2006 6:08 am    Post subject: Re: reading key squence from keypad Reply with quote

Here is the source code :

;PASSWORD Source code :
;Using keypad to catch data and drive LED when the password is correct
;For this example the password is 3 4 5
;In this lesson we'll scan keypad and get data out to LED-P0
row1 bit P2.4
row2 bit P2.5
row3 bit P2.6
row4 bit P2.7
col1 bit P2.0
col2 bit P2.1
col3 bit P2.2
col4 bit P2.3
;
keydata equ 70h
keybounc equ 71h
keyport equ P2
org 0h
pass3: call keypad4x4 ;calling subroutine keypad4x4
Mov A,keydata ;A = keydata
cjne A,#3,pass3 ;detects key 3
;
pass4: call keypad4x4
mov A,keydata
cjne A,#4,pass4 ;detects key 4
;
pass5: call keypad4x4
mov A,keydata
Cjne A,#5,pass5;detects key 5
;
send: CPL A ;A = NOT A
Mov P0,A ;P0 = A
Sjmp send ;LOOPING FOREVER PART 2
;
delay: mov R0,#0
delay1:mov R2,#50
djnz R2,$
djnz R0,delay1
ret
;
;====================================
; subroutine scan keypad 4x4
;====================================
Keypad4x4:
mov keybounc,#50 ;keybounc = 50
mov keyport,#0FFh ;keyport=P2= FF
clr col1 ;col1= P3.0 = 0
Detect:jb row1,key1 ;jump to key1 if row1=1
djnz keybounc,Detect
mov keydata,#00h ;Keydata =00h
ret
;
key1: jb row2,key2 ;jump to Key2 if row2=1
djnz keybounc,key1
mov keydata,#04h ;Keydata = 04h
ret
;
key2: jb row3,key3 ; idem
djnz keybounc,key2
mov keydata,#08h
ret
;
key3: jb row4,key4 ; idem
djnz keybounc,key3
mov keydata,#0Ch
ret
;
key4: setb col1
clr col2
jb row1,key5
djnz keybounc,key4
mov keydata,#01h
ret
;
key5: jb row2,key6
djnz keybounc,key5
mov keydata,#05h
ret
;
key6: jb row3,key7
djnz keybounc,key6
mov keydata,#09h
ret
;
key7: jb row4,key8
djnz keybounc,key7
mov keydata,#0Dh
ret
;
key8: setb col2
clr col3
jb row1,key9
djnz keybounc,key8
mov keydata,#02h
ret
;
key9: jb row2,keyA
djnz keybounc,key9
mov keydata,#06h
ret
;
keyA: jb row3,keyB
djnz keybounc,keyA
mov keydata,#0Ah
ret
;
keyB: jb row4,keyC
djnz keybounc,keyB
mov keydata,#0Eh
ret
;
keyC: setb col3
clr col4
jb row1,keyD
djnz keybounc,keyC
mov keydata,#03h
ret
;
keyD: jb row2,keyE
djnz keybounc,keyD
mov keydata,#07h
ret
;
keyE: jb row3,keyF
djnz keybounc,keyE
mov keydata,#0Bh
ret
;
keyF: jb row4,Nokey
djnz keybounc,keyF
mov keydata,#0Fh
ret
Nokey:mov keydata,#0FFh
ret
;================================
;The end of Keypad 4x4 subroutine
;================================
end
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    mytutorialcafe.com Forum Index -> Interfacing with Microcontroller All times are GMT
Page 1 of 1

 
Jump to:  
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group