Product categories

Have You Seen

B0505S-1WR3 MORNSUN Isolated DC - DC Converter

B0505S-1WR3 MORNSUN Isolated DC - DC Converter

Mornsun B0505S-1WR3 DC-DC Isolated ConverterMORNSUN B0505S 1WR3 1 watt, 5 Volts Isolated DC to DC Po..

Rs.106.20 (inc GST)
Rs.90.00 + GST

SKU: 2969 | DAE663
Stock: 100
XL1509-Adj E1 Buck DC to DC Converter IC (SOP8L Package)

XL1509-Adj E1 Buck DC to DC Converter IC (SOP8L Package)

XL1509-Adj E1 Buck DC to DC Converter IC (SOP8L Package)XL1509-Adj E1 Buck DC to DC Converter IC, Ad..

Rs.25.96 (inc GST)
Rs.22.00 + GST

SKU: 3657 | DAF397
Stock: 485

Matrix Keypad Interfacing



For Circuit and more theory of Interfacing Matrix Keypad to Microcontroller click here.

The subroutine check_keypad can be used to directly interface any 4X3 matrix keypad. It checks if any switch on the matrix keypad is pressed. If any of the switch is pressed then the switch is debounced and we wait until the switch has been released. Once the switch has been released the switch number is loaded into the accumulator and the carry flag is set to indicate that a switch has been pressed. If NO switch has been pressed then the accumulator is cleared and the carry flag is also cleared to indicate no switch has been pressed.

 

column1 bit P1.0
column2 bit P1.1
row1 bit P1.3
row2 bit P1.4
row3 bit P1.5
row4 bit P1.6

check_keypad:

clr column1

setb column2 ;Select Column 1
setb column3

jnb row1,c1_check_keypad

jnb row2,c2_check_keypad

jnb row3,c3_check_keypad

jnb row4,c4_check_keypad

setb column1
clr column2 ;Select Column 2
setb column3

jnb row1,c5_check_keypad

jnb row2,c6_check_keypad

jnb row3,c7_check_keypad

jnb row4,c8_check_keypad

setb column1
setb column2 ;Select Column 3
clr column3
jnb row1,c9_check_keypad

jnb row2,c10_check_keypad

jnb row3,c11_check_keypad

jnb row4,c12_check_keypad

setb column1

setb column2

setb column3

mov a,#00h ;Since no switch has been pressed so Acc=00h
clr c ;and C=0
ret
c1_check_keypad: //column 1, row 1
mov r7,#00h

deb1_check_keypad:

;debounce row 1 switch
jb row1,r1_check_keypad

djnz r7,deb1_check_keypad

jnb row1,$ ;wait till switch is released
mov a,#1 ;since switch pressed is 1, Acc =1
setb c ;Indicating switch has been pressed
setb column1
ret

r1_check_keypad:

setb column1 ;Error while debouncing so return
mov a,#0

clr c

ret

c2_check_keypad: //column 1, row2
mov r7,#00h
deb2_check_keypad: ;debounce row 2 switch

jb row2,r2_check_keypad

djnz r7,deb2_check_keypad

jnb row2,$ ;wait till switch is released
mov a,#4 ;since switch pressed is 4, Acc =4
setb c ;Indicating switch has been pressed
setb column1
ret

r2_check_keypad:

setb column1

;Error while debouncing so return

mov a,#0

clr c

ret

c3_check_keypad: //column 1, row3
mov r7,#00h

deb3_check_keypad: ;debounce row 3 switch

jb row3,r3_check_keypad

djnz r7,deb3_check_keypad

jnb row3,$                                                     ;wait till switch is released

mov a,#7                                                      ;since switch pressed is 7, Acc =7

setb c                                                            ;Indicating switch has been pressed

setb column1

ret

r3_check_keypad:

setb column1                                             ;Error while debouncing so return

mov a,#0

clr c

ret


c4_check_keypad:                                             //column 1, row4

mov r7,#00h

deb4_check_keypad:                                       ;debounce row 4 switch

jb row4,r4_check_keypad

djnz r7,deb4_check_keypad


jnb row4,$                                                ;wait till switch is released

mov a,#10                                               ;since switch pressed is 10, Acc =10

setb c                                                       ;Indicating switch has been pressed

setb column1

ret

r4_check_keypad:

setb column1                                       ;Error while debouncing so return

mov a,#0

clr c

ret


c5_check_keypad:                                            //column 2, row 1

mov r7,#00h

deb5_check_keypad:                                        ;debounce row 1 switch

jb row1,r5_check_keypad

djnz r7,deb5_check_keypad


jnb row1,$                                                 ;wait till switch is released

mov a,#2                                                  ;since switch pressed is 2, Acc =2

setb c                                                        ;Indicating switch has been pressed

setb column2

ret

r5_check_keypad:

setb column2                                          ;Error while debouncing so return

mov a,#0

clr c

ret


c6_check_keypad:                                          //column 2, row2

mov r7,#00h

deb6_check_keypad:                                    ;debounce row 2 switch

jb row2,r6_check_keypad

djnz r7,deb6_check_keypad


jnb row2,$                                            ;wait till switch is released

mov a,#5                                             ;since switch pressed is 5, Acc =5

setb c                                                   ;Indicating switch has been pressed

setb column2

ret

r6_check_keypad:

setb column2                                   ;Error while debouncing so return

mov a,#0

clr c

ret


c7_check_keypad:                                   //column 2, row3

mov r7,#00h

deb7_check_keypad:                              ;debounce row 3 switch

jb row3,r7_check_keypad

djnz r7,deb7_check_keypad


jnb row3,$                                          ;wait till switch is released

mov a,#8                                           ;since switch pressed is 8, Acc =8

setb c                                                 ;Indicating switch has been pressed

setb column2

ret

r7_check_keypad:

setb column2                                    ;Error while debouncing so return

mov a,#0

clr c

ret


c8_check_keypad:                                     //column 2, row4

mov r7,#00h

deb8_check_keypad:                                ;debounce row 4 switch

jb row4,r8_check_keypad

djnz r7,deb4_check_keypad


jnb row4,$                                          ;wait till switch is released

mov a,#11                                         ;since switch pressed is 11, Acc =11

setb c                                                 ;Indicating switch has been pressed

setb column2

ret

r8_check_keypad:

setb column2                                    ;Error while debouncing so return

mov a,#0

clr c

ret


c9_check_keypad:                                    //column 3, row 1

mov r7,#00h

deb9_check_keypad:                              ;debounce row 1 switch

jb row1,r9_check_keypad

djnz r7,deb9_check_keypad


jnb row1,$                                         ;wait till switch is released

mov a,#3                                           ;since switch pressed is 3, Acc =3

setb c                                                 ;Indicating switch has been pressed

setb column3

ret

r9_check_keypad:

setb column3                                    ;Error while debouncing so return

mov a,#0

clr c

ret


c10_check_keypad:                                   //column 3, row2

mov r7,#00h

deb10_check_keypad:                             ;debounce row 2 switch

jb row2,r10_check_keypad

djnz r7,deb10_check_keypad


jnb row2,$                                          ;wait till switch is released

mov a,#6                                           ;since switch pressed is 6, Acc =6

setb c                                     

Written by


Website: