| ??? 08/28/06 06:00 Read: times |
#123176 - WHOLE code Responding to: ???'s previous message |
>;_________________________________________________________________
;---------------KEY PAD SUBROUTINE STARTS HERE--------------------
;_________________________________________________________________
keypad_reset:
push acc
;------------------------------------------------------------------
mov p0,#0f0h ; all columns high n rows low
mov a,p0
anl a,#01110000b ; consider only columns
cjne a,#01110000b,keypad_reset ; initially check for all keys released
;------------------------------------------------------------------
pop acc
ret
;-------------------------------------------------------------------
keypad_ready:
push acc
;-------------------------------------------------------------------
keypad_ready1:
mov p0,#0f0h ; all columns high n rows low
mov a,p0
anl a,#01110000b ; consider only columns
cjne a,#01110000b,keypad_ready1 ; initially check for all keys released
;-------------------------------------------------------------------
ks_loop1:
acall delay_16ms
mov a,p0
anl a,#01110000b ; scan columns
cjne a,#01110000b,debounce ; if key pressed, check debounce
sjmp ks_loop1 ; if not, keep checking for key pressed
;-------------------------------------------------------------------
debounce:
acall delay_16ms
mov a,p0
anl a,#01110000b
cjne a,#01110000b,check_row
sjmp ks_loop1
;--------------------------------------------------------------------
check_row:
clr ROW3
setb ROW2
setb ROW1
setb ROW0
mov a,p0
anl a,#01110111b ;test row zero
cjne a,#01110111b,row_3
;--------------------------------------------------------------------
setb ROW3
clr ROW2
setb ROW1
setb ROW0
mov a,p0
anl a,#01111011b ;test row one
cjne a,#01111011b,row_2
;--------------------------------------------------------------------
setb ROW3
setb ROW2
clr ROW1
setb ROW0
mov a,p0
anl a,#01111101b ;test row two
cjne a,#01111101b,row_1
;---------------------------------------------------------------------
setb ROW3
setb ROW2
setb ROW1
clr ROW0
mov a,p0
anl a,#01111110b ;test row three
cjne a,#01111110b,row_0
;----------------------------------------------------------------------
sjmp ks_loop1
;----------------------------------------------------------------------
row_0:
mov dptr,#disp_kcode0 ;if row zero is press, point dptr to first digit of row zero
sjmp find_num
row_1:
mov dptr,#disp_kcode1 ;if row one is press, point dptr to first digit of row one
sjmp find_num
row_2:
mov dptr,#disp_kcode2 ;if row two is press, point dptr to first digit of row two
sjmp find_num
row_3:
mov dptr,#disp_kcode3 ;if row three is press, point dptr to first digit of row three
sjmp find_num
;----------------------------------------------------------------------
find_num: rlc a
find_num1: rlc a
jnc found_num ;which column is pressed/grounded
inc dptr
sjmp find_num1
;----------------------------------------------------------------------
found_num: clr a
movc a,@a+dptr
mov TEMP_DIGIT,a
pop ACC
ret
;-----------------------------------------------------------------------
disp_kcode0:DB' ','a','d'
disp_kcode1:DB'g','j','m'
disp_kcode2:DB'p','t','w'
disp_kcode3:DB'*','0','#'
;-----------------------------------------------------------------------
;_________________________________________________________________
;----------------KEY PAD SUBROUTINE ENDS HERE---------------------
;_________________________________________________________________
;___________________________________________________________________________
;------------------------MKP subroutines start here-------------------------
;___________________________________________________________________________
;--------------------------------------------------
;setting no of taps(count) for different buttons starts here
;--------------------------------------------------
SET_COUNT:
PUSH ACC
PUSH 00H
MOV A,FIRST_DIGIT
COUNT4ONE:
CJNE A,#' ',COUNT4ZERO
MOV COUNT,#10H ;10h => 16characters(' ' to '/')
SJMP SET_COUNT1
COUNT4ZERO:
CJNE A,#'0',COUNT4SEVEN
MOV COUNT,#11H ;11h => 17characters('0' to '@')
SJMP SET_COUNT1
COUNT4SEVEN:
CJNE A,#'7',COUNT4NINE
MOV COUNT,#04H ;04h => 4characters('p' to 's')
SJMP SET_COUNT1
COUNT4NINE:
CJNE A,#'9',COUNT4STAR
MOV COUNT,#04H ;04h => 4characters('w' to 'z')
SJMP SET_COUNT1
COUNT4STAR:
CJNE A,#'*',COUNT4HASH
MOV COUNT,#04H ;04h => 4characters('*' to '-')
SJMP SET_COUNT1
COUNT4HASH:
CJNE A,#'#',COUNT4REST
MOV COUNT,#04H ;04h => 4characters('#' to '&')
SJMP SET_COUNT1
COUNT4REST:
MOV COUNT,#03H ;03h => 3characters(for the rest of the buttons)
SET_COUNT1:
MOV TEMP_COUNT,COUNT
POP 00H
POP ACC
RET
;--------------------------------------------------
;setting no of taps(count) for different buttons ends here
;--------------------------------------------------
;--------------------------------------------------
;--scanning no of taps on same button starts here--
;--------------------------------------------------
SECOND_KEY_SCAN:
PUSH 00H
PUSH 01H
PUSH 02H
PUSH ACC
WAIT1:
MOV R0,#03H ; values of r0,r1 & r2 together provide a delay of 423ms
WAIT2:
MOV R1,#0FFH
WAIT3:
MOV R2,#0FFH
CONFIRM_KEY_PRESS:
MOV A,P0 ; p0.0 t0 p0.3 => rows, p0.4 to 0.6 => columns
ANL A,#01110000b ; scan columns
cjne a,#01110000b,KEY_PRESS_CONFIRMED ; if key pressed within 423ms, come out of delay loop
DJNZ R2,CONFIRM_KEY_PRESS
DJNZ R1,WAIT3
DJNZ R0,WAIT2
SJMP SECOND_KEY_SCAN1 ; if no key is pressed within 423ms, come out of key checking subroutine
KEY_PRESS_CONFIRMED:
ACALL KEYPAD_READY ; this routine scans the keypad and puts the pressed button's value to TEMP_DIGIT
MOV A,TEMP_DIGIT
CJNE A,FIRST_DIGIT,SECOND_KEY_SCAN1 ; if currently pressed key's noy equal to previously pressed, come out of this routine
INC DIGIT ; INCREMENTING DIGIT CONTENTS => NEXT CHARACTER OF CORRESPONDING KEY
DJNZ TEMP_COUNT,WAIT1 ; decrement the loop around count and jmp back to checking key pressed
MOV TEMP_COUNT,COUNT ; if loop around, reload the count
MOV DIGIT,FIRST_DIGIT ; if loop around, reload button's first value
SJMP WAIT1
SECOND_KEY_SCAN1:
POP ACC
POP 02H
POP 01H
POP 00H
RET
;--------------------------------------------------
;---scanning no of taps on same button ends here---
;--------------------------------------------------
;___________________________________________________________________________
;-------------------------MKP subroutines end here--------------------------
;___________________________________________________________________________
DISP_MOBILE_KPAD: DB " MOBILE KEYPAD "
;--------------------------------------------------
;--------------------------------------------------
MKP_MAIN:
CLR RS
CLR EN
CLR RW
MOV SP,#65H
MOV IE,#00H
MOV P1,#00H ; 4BIT LCD
MOV P0,#0FFH ; INPUT PORT FOR KEYPAD INTERFACE
ACALL LCD4_INITIALISE ;4bit lcd initialisation
ACALL KEYPAD_RESET ;make sure all keys are released on reset
MKP_MAIN0:
MOV R0,#10H ;bring cursor bck to line2
ACALL LINE2
MKP_MAIN1:
ACALL KEYPAD_READY ; FINDS OUT THE KEY PRESSED AND PUTS THE FIRST CHARACTER OF CORRESPONDING KEY IN 'DIGIT'(31H)
MOV FIRST_DIGIT,TEMP_DIGIT ;makes copies of pressed key into first_digit and temp_digit
MOV DIGIT,TEMP_DIGIT ;copies are used in second_key_scan
ACALL SET_COUNT
MKP_MAIN2:
ACALL SECOND_KEY_SCAN
MOV LCD_DATA,DIGIT ;display pressed key on lcd
ACALL DATW
DJNZ R0,MKP_MAIN1
SJMP MKP_MAIN0
END
|
| Topic | Author | Date |
| problem with delays | 01/01/70 00:00 | |
| Omitted pull-ups at Port 0? | 01/01/70 00:00 | |
| No, it's pulled high | 01/01/70 00:00 | |
| You should see the connection... | 01/01/70 00:00 | |
| could it be your approach? | 01/01/70 00:00 | |
| p0 initialised as input port | 01/01/70 00:00 | |
| post the WHOLE code | 01/01/70 00:00 | |
| WHOLE code | 01/01/70 00:00 | |
| Try this | 01/01/70 00:00 | |
| WHOLE code | 01/01/70 00:00 | |
| Assuming that the external pullups are not working | 01/01/70 00:00 | |
| why is the delay not being excecuted? | 01/01/70 00:00 | |
| HOW DO YOU KNOW | 01/01/70 00:00 | |
| Through debugging | 01/01/70 00:00 | |
| I know nothing about keil debugger | 01/01/70 00:00 | |
| make code that resembles the flowchart and you wil | 01/01/70 00:00 | |
| whole? | 01/01/70 00:00 | |
| Ashwins stack handling is totally unsuited! | 01/01/70 00:00 | |
| to generate tone of octave(8keys)with 89c51 | 01/01/70 00:00 | |
sandy please start a new thread | 01/01/70 00:00 |



