org 0004h
;====================================================================
;TMR2 interrupt rate = 4mS
;====================================================================
btfss PIR1,TMR2IF
goto ISR_Exit
bcf PIR1,TMR2IF
;
decfsz Key_Counter,F
goto Multiplex_Display
movlw .4
movwf Key_Counter
;-------------------------------------------------------------------
;KEY read rate = 4mS X 4 = 16mS
Read_Keys
BANKSEL LATB
clrf LATB ; clear segment data
clrf LATA ; clear common cathodes
BANKSEL PORTB
clrf PORTB
BANKSEL TRISB
movlw b'00001111' ; make RB0,1,2,3 = inputs for a short time
movwf TRISB
BANKSEL WPUB
movlw b'00001111'
movwf WPUB
BANKSEL PORTB
btfss PORTB,0
bsf SW_Flag,SW_1
btfss PORTB,1
bsf SW_Flag,SW_2
btfss PORTB,2
bsf SW_Flag,SW_3
btfss PORTB,3
bsf SW_Flag,SW_4
;==================================================
;Display Multiplex @ 4mS rate
;Common Cathodes [RA0=D1, RA1=D2, RA2=D3,RA3=D4]
;==================================================
Multiplex_Display
BANKSEL LATB
clrf LATB ; clear segment data
clrf LATA ; clear common cathodes
movlb 00h ; back to Bank 0
btfss Display_Select,0
goto Display_1
btfss Display_Select,1
goto Display_2
btfss Display_Select,2
goto Display_3
goto Display_4
;
Display_1 movf Digit_1,W ; Show D1 segment
call Segment_Table ; //
movlb 01h ; Bank 1
movwf LATB
bsf LATA,0 ; turn on D1
movlb 00h ; back to Bank 0
bsf Display_Select,0
goto ISR_Exit
Display_2 movf Digit_2,W ; Show D2 segment
call Segment_Table ; //
movlb 01h ; Bank 1
movwf LATB
bsf LATA,1 ; turn on D1
movlb 00h ; back to Bank 0
bsf Display_Select,1
goto ISR_Exit
Display_3 movf Digit_3,W ; Show D3 segment
call Segment_Table ; //
movlb 01h ; Bank 1
movwf LATB
bsf LATA,2 ; turn on D1
movlb 00h ; back to Bank 0
bsf Display_Select,2
goto ISR_Exit
Display_4 movf Digit_4,W ; Show D4 segment
call Segment_Table ; //
movlb 01h ; Bank 1
movwf LATB
bsf LATA,3 ; turn on D1
movlb 00h ; back to Bank 0
clrf Display_Select
;
Backup_Digits movf S_Digit_1,W ; 1
movwf Digit_1
movf S_Digit_2,W ; 2
movwf Digit_2
movf S_Digit_3,W ; 3
movwf Digit_3
movf S_Digit_4,W ; 4
movwf Digit_4
ISR_Exit
retfie