;------------------------------------------------------------------------------- ;------------------------------ Define Symbols ------------------------------- ;------------------------------------------------------------------------------- #define LCDen LATC, 3, 1 #define LCDrw LATC, 2, 1 #define LCDrs LATC, 1, 1 #define Row1 PORTB, 7, 1 #define Row2 PORTB, 6, 1 #define Row3 PORTB, 5, 1 #define Row4 PORTB, 4, 1 #define Col1 LATB, 3, 1 #define Col2 LATB, 2, 1 #define Col3 LATB, 1, 1 #define Col4 LATB, 0, 1 cat call Keyscan ;------------------------------------------------------------------------------- ;---------------------------------- Keypad ----------------------------------- ;------------------------------------------------------------------------------- Keyscan bcf Col1 bcf Col2 bcf Col3 ; Check if a key has been pressed bcf Col4 btfss Row1 goto scanprocess btfss Row2 goto scanprocess btfss Row3 goto scanprocess btfsc Row4 goto Keyscan scanprocess bcf Col1 ; Check which key has been pressed bsf Col2 bsf Col3 bsf Col4 movlw d'1' call Rscan bsf Col1 movlw d'2' bcf Col2 call Rscan bsf Col2 movlw d'3' bcf Col3 call Rscan bsf Col3 movlw d'4' bcf Col4 call Rscan bsf Col4 goto Keyscan Rscan btfss Row1 ; Which row? goto R1set btfss Row2 goto R2set btfss Row3 goto R3set btfss Row4 goto R4set return R1set addlw d'0' goto clrct R2set addlw d'4' goto clrct R3set addlw d'8' goto clrct R4set addlw d'12' clrct movwf temp1, 0 decf STKPTR, f, 1 Keynot call d50ms ; 50ms debounce bcf Col1 bcf Col2 bcf Col3 ; Check when key is depressed bcf Col4 btfss Row1 goto Keynot btfss Row2 goto Keynot btfss Row3 goto Keynot btfss Row4 goto Keynot movlw LOW table ; take low table address addwf temp1, w, 0 ; add to temp1, acts as an offset movwf TBLPTRL, 1 ; Move low table pointer clrf TBLPTRH movlw HIGH table addwfc TBLPTRH, f, 1 ; add high table address and carry ; if there was one from last addwf clrf TBLPTRU movlw UPPER table ; do same for upper table address addwf TBLPTRU, f, 1 tblrd * ; Read the contents via TBLPTR movf TABLAT, w, 1 ; Move results into working register return table db "1", "1", "2", "3", "A", "4", "5", "6" ; our data table db "B", "7", "8", "9", "C", "*", "0", "#" db "D" ;------------------------------------------------------------------------------- ;------------------------------ Delay Routines ------------------------------- ;------------------------------------------------------------------------------- delay movlw d'100' ; 125ns 1 second delay movwf b0_temp3, 0 ; 125ns nop ; 125ns label_3 movlw d'40' ; 125ns movwf b0_temp2, 0 ; 125ns nop ; 125ns nop ; 125ns label_1 movlw d'249' ; 125ns movwf b0_temp, 0 ; 125ns nop ; 125ns nop ; 125ns label_2 nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns decfsz b0_temp, f, 0 ; 125ns goto label_2 ; 250ns (1us total inner loop) ; 125ns decfsz b0_temp2, f, 0 ; 125ns goto label_1 ; 250ns ; 125ns decfsz b0_temp3, f, 0 ; 125ns goto label_3 ; 250ns return d50ms movlw d'1' ; 50ms delay movwf b0_temp3, 0 goto label_3 micro100 movlw d'100' ; 100us delay movwf b0_temp, 0 label_4 nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns nop ; 125ns decfsz b0_temp, f, 0 ; 125ns goto label_4 ; 250ns (1us total inner loop) return end