Sun May 19, 2013 1:46 pm
TITLE "SCANNING THE KEYPAD"
list p = 16f877
include <p16f877.inc>
BANK0 macro
bcf STATUS,RP0
bcf STATUS,RP1
endm
BANK1 macro
bsf STATUS,RP0
bcf STATUS,RP1
endm
BANK2 macro
bcf STATUS,RP0
bsf STATUS,RP1
endm
BANK3 macro
bsf STATUS,RP0
bsf STATUS,RP1
endm
;*
DELAY_TIME EQU 0x20
KEYDATA EQU 0x21
TEMP EQU 0x22
;****
ORG 0
NOP
GOTO START
;***
; MAIN ROUTINE
ORG 0x20
START CALL INIT ;INITIALISE PORTS
AGAIN MOVLW 1 ;SET ROW 1 HIGH
MOVWF PORTD ;AND OUTPUT
BTFSS PORTD,7 ;TEST COLUMN 1 No 3
GOTO SIX ;IF NOT 3, TRY 6
MOVLW 3 ;ELSE STORE 3
MOVWF KEYDATA ;IN KEyDATA
GOTO LAST ;AND FINISH
SIX BTFSS PORTD,6 ;TEST COLUMN 1 No €
GOTO NINE ;IF NOT 6, TRY 9
MOVLW 6 ;ELSE STORE 6
MOVWF KEYDATA ;IN KEyDATA
GOTO LAST :AND FINISH
NINE BTFSS PORTD,5 ;TEST COLUMN 1 No 5
GOTO NUM ;IF NOT 5, TRY NUM *
MOVLW 9 ;ELSE STORE 9
MOVWF KEYDATA ;IN KEyDATA
GOTO LAST ;AND FINISH
NUM BTFSS PORTD,4 ;TEST cOLUMN 1 NUM *
GOTO COL2 ;IF NOT NUM, TRY COL 2
MOVLW 0FFH ;ELSE SToRE FFH
MOVWF KEYDATA ;IN KEyDATA
GOTO LAST ;AND FINISH
COL2 MOVLW 2 ;SET ROW 2 HIGH
MOVWF PORTD ;AND OUTPUT
BTFSS PORTD,7 ;TEST COLUMN 2 No 2
GOTO FIVE ;IF NOT 2, TRY 5
MOVLW 2 ;ELSE STORE 2
MOVWF KEYDATA ;IN KEyDATA
GOTO LAST ;AND FINISH
FIVE BTFSS PORTD,6 ;TEST COLUMN 2 No 5
GOTO EIGHT ;IF NOT 5, TRY
MOVLW 5 ;ELSE SToRE 5
MOVWF KEYDATA ;IN KEYDATA
GOTO LAST ;AND FINISH
EIGHT BTFSS PORTD,5 ;TEST COLJMN 2 No 8
GOTO NONE ;IF NOT 8, TRY 0
MOVLW 8 ;EISE STORE 8
MOVWF KEYDATA ;IN KEYDATA
GOTO LAST ;AND FINISH
NONE BTFSS PORTD,4 ;TEST COIIJMN 2 No 0
GOTO COL3 ;IF NoT ZERo, TRy CoL 3
MOVLW 0 ;ELSE SToRE 0
MOVWF KEYDATA ;IN KEYDATA
GOTO LAST ;AND FINISH
C0L3 MOVLW 4 ;SET RoW 3 HIGH
MOVWF PORTD ;AND OUTPUT
BTFSS PORTD,7 ;TEST cOLJw’iN 3 No 1
GOTO FOUR ;IF NoT 1, TRy 4
MOVLW 1 ;ELSE SToRE 1
MOVWF KEYDATA ;IN KEYDATA
GOTO LAST ; AND FINISH
FOUR BTFSS PORTD,6
GOTO SEVEN
MOVLW 4
MOVWF KEYDATA
GOTO LAST
SEVEN BTFSS PORTD,5 ;TEST COLJ 3 No 7
GOTO STAR ;IF NOT 7, TRY
MOVLW 7 ;ELSE SToRE 7
MOVWF KEYDATA ;|IN KEYDATA
GOTO LAST ;AND FINISH
STAR BTFSS PORTD,4 ;TEST COLJMN 3 ‘
GOTO LOOP ;IF NOT a, TRY REPEAT
MOVLW 0FFH ;ELSE SToRE FF11
MOVWF KEYDATA ;IN KEYDATA
GOTO LAST ;AND FINISH
LAST CALL DELAY ;DEBoUNDz KEYPAD
LOOP MOVF PORTD,W ;READ PORT
ANDLW 0F0H ;MASK OL5
BTFSS STATUS,Z ;AND WAIT TILL No PRESSED
GOTO LOOP
GOTO AGAIN ;Do AGAIN
; PORT INTIAlISATION
INIT BANK1 ;SET To BANK 1
MOVLW 0xF0 ;SET BITS 0-3 AS oUT, 4-7 AS IN
MOVWF TRISD
BANK0 ;BACK To BANK 0
RETURN
; DELAy RotJTIN
DELAY MOVWF TEMP ;SAvE W
MOVLW 0xFF
MOVWF DELAY_TIME
WAIT INCFSZ DELAY_TIME
GOTO WAIT
MOVF TEMP,W
RETURN
END
Codemiles.com is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com
Powered by phpBB © phpBB Group.