INTERRUPTS_ISR
; Save context:
MOVWF W_TEMP ; save off current W register contents
MOVF STATUS,w ; move status register into W register
MOVWF STATUS_TEMP ; save off contents of STATUS register
MOVF FSR,W ; Save FSR register
MOVWF FSR_TEMP ; to FSR_TEMP
MOVF PCLATH,w ; move pclath register into w register
MOVWF PCLATH_TEMP ; save off contents of PCLATH register
CLRF PCLATH ; Clear PCLATH
; (Select PAGE 0)
CLRF STATUS ; Clear STATUS
; (Select BANK 0)
BTFSC PIE1,TMR1IE ; Timer1 overflow interrupt?
GOTO INT_TMR1 ; Yes.
BTFSS INTCON,T0IF ; Timer0 overflow interrupt?
GOTO END_INT ; No.
INT_TMR0
EXIT_TMR0_INT
;BCF INTCON,T0IF ; Clear TMR0 interrupt flag
;GOTO END_INT ; Exit interrupt
INT_TMR1
BCF PIR1,TMR1IF ; Clear Timer1 Interrupt flag
MOVLW 0x30;0x18 ;
MOVWF TMR1L ;
MOVLW 0xF8;0xFC ;
MOVWF TMR1H ; Init TIMER1 with decimal 64536 (interrupt every 1ms)
BSF LED_CMN ; Leds OFF
BSF DISP3 ; Display3 OFF
BSF DISP2 ; Display2 OFF
BSF DISP1 ; Display1 OFF
CLRF PORTA
CLRF PORTB
BTFSS LEDS_S,1 ; Are we in temperature mode?
GOTO timermode ; No, we are in timer mode
MOVF TEMPER,W ; Put temperature in W
;INCF TEMPER,F
CALL bin2bcd ; Decode temperature to bcd
GOTO ll2 ; continue
timermode:
MOVF TIMER,W ; Put time in W
INCF TIMER,F
CALL bin2bcd ; Decode time to bcd
ll2:
INCF INDEX_DISP,F ; Increment display index
MOVLW D'3' ; Limit counter from 0 to 3
ANDWF INDEX_DISP,F ; " " "
MOVLW D'0'
XORWF INDEX_DISP,W ; If index = 0
BTFSC STATUS,Z ; Then it's time
GOTO SETLEDS ; to show LEDS
MOVLW D'1'
XORWF INDEX_DISP,W ; If index = 1
BTFSC STATUS,Z ; Then it's time
GOTO SETDISP3 ; to show DISPLAY1
MOVLW D'2'
XORWF INDEX_DISP,W ; If index = 2
BTFSC STATUS,Z ; Then it's time
GOTO SETDISP2 ; to show DISPLAY2
MOVLW D'3'
XORWF INDEX_DISP,W ; If index = 3
BTFSC STATUS,Z ; Then it's time
GOTO SETDISP1 ; to show DISPLAY3
;Leds stuff
SETLEDS
BCF LED_UP ; Led UP always on
BCF LED_DWN ; Led DWN always on
BTFSC LEDS_S,3 ; Is led light on?
GOTO $+3
BSF LED_LIGHT ; No
GOTO $+2
BCF LED_LIGHT ; Yes
BTFSC LEDS_S,2 ; Is led toast on?
GOTO $+3
BSF LED_TOASTER ; No
GOTO $+2
BCF LED_TOASTER ; Yes
BTFSC LEDS_S,5 ; Is led time on?
GOTO $+3
BSF LED_TIMER ; No
GOTO $+2
BCF LED_TIMER ; Yes
BTFSC LEDS_S,1 ; Is led temp on?
GOTO $+3
BSF LED_TEMP ; No
GOTO $+2
BCF LED_TEMP ; YES
BCF LED_CMN ; Leds ON
GOTO $+1 ; 2 us delay (transistor response time)
GOTO CONT_INT
SETDISP3
MOVF HUNDREDS,W ; Test to see if HUNDREDS
XORLW D'0' ; are zero (00) so
BTFSC STATUS,Z ; we turn display off
GOTO CONT_INT
MOVF HUNDREDS,W ; copy again hundeds to W (was cleared?)
CALL DECDISP_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF HUNDREDS,W ; copy hundeds to W
CALL DECDISP_B ; convert
MOVWF PORTB ; put it in PORTB
BCF DISP3 ; display 3 on
GOTO $+1 ; 2 us delay (transistor response time)
GOTO CONT_INT
SETDISP2
MOVF HUNDREDS,W ; Test to see if HUNDREDS
XORLW D'0' ; are zero (00) so
BTFSS STATUS,Z ; if TENS are also 0, we turn it off.
GOTO CONTTENS
MOVF TENS,W ; If we get here, HUNDREDS are zero, so test to see if TENS also 0
XORLW D'0' ; Are TENS = 0?
BTFSC STATUS,Z ; Test it
GOTO CONT_INT ; Yes, let both HUNDREDS and TENS digits off!
CONTTENS
MOVF TENS,W ; copy tens to W
CALL DECDISP_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF TENS,W ; copy tens to W
CALL DECDISP_B ; convert
MOVWF PORTB ; put it in PORTB
BCF DISP2 ; display 2 on
GOTO $+1 ; 2 us delay (transistor response time)
GOTO CONT_INT
SETDISP1
MOVF UNITS,W ; copy UNITS to W
CALL DECDISP_A ; convert
MOVWF PORTA ; put it in PORTA
MOVF UNITS,W ; copy UNITS to W
CALL DECDISP_B ; convert
MOVWF PORTB ; put it in PORTB
BCF DISP1 ; display 1 on
GOTO $+1 ; 2 us delay (transistor response time)
GOTO CONT_INT
CONT_INT
INCF TMR_1MS,F ; Increment TR_1MS (1 ms counter)
MOVLW D'100'
XORWF TMR_1MS,W ; Is TMR_1MS = 100?
BTFSC STATUS,Z ; No, skip if TMR_1MS < 100
GOTO INC100MS ; Yes, zero TMR_1MS and inc TMR_100MS
GOTO END_INT ; No, exit interrupt
INC100MS
CLRF TMR_1MS ; Zero TMR_1MS
INCF TMR_100MS,F ; Increment TMR_100MS (100 ms counter)
MOVLW D'4' ; 500 ms?
XORWF TMR_100MS,W ; Is TMR_100MS = 5 (500ms)?
BTFSC STATUS,Z ; No, skip if TMR_100MS < 5
GOTO INCCONTA ; Yes, zero TMR_100MS and inc 0,5 seconds counter
GOTO END_INT ; No, Exit interrupt
INCCONTA
CLRF TMR_100MS ; Zero 100 ms counter (reached 500ms)
BTFSS LEDS_S,7 ; Is led blink enabled?
GOTO LEDOUT ; No, it's not enabled
MOVLW D'1' ; Verify if ...
XORWF T1_CONTA,W ; passed 1/2 second ...
BTFSC STATUS,Z ;
GOTO LEDON ; Led ONOFF is ON? Goto LEDON
LEDOFF
BCF LED_ONOFF ; Turn OFF LEDON_OFF
GOTO LEDOUT ; ok, done...
LEDON
BSF LED_ONOFF ; Turn ON LED_ONOFF
LEDOUT
DECFSZ T1_CONTA,F ; Decrement the Counter Register
GOTO END_INT ; If diferent of zero, exit interrupt
MOVLW 2 ;
MOVWF T1_CONTA ; Restart Counter Register with 2
GOTO END_INT
END_INT