|
Subtitle "-- Interrupt service routine --"
Page
;
; 07-Dec-98 BK Initial edit
; 25-Jan-99 BK Last update
;
; ** IntServ -- Interrupt service routine
;
IntServ:
movwf WSave ; Save W register in Buffer
swapf STATUS, w ; Swap status to be saved into W
bcf STATUS, RP0 ; Select Bank 0
movwf StatSave ; Save status
movfw PCLATH ; Save PC high byte
movwf PCHSave ;
clrf PCLATH ; Select Page 0 of the program memory
btfss PIR1, PBIF ; See if the RTC interrupt
goto TryADCInt ; Branch if NORTCInterrupt: ; Real-Time clock interrupt
bsf _1SEC_BIT ; Set 1 sec. interval flag
bcf PIR1, PBIF ; Clear the RTC interrupt flag
btfss gFlags, Process_BIT ; Are we waiting the next point processing time for?
goto rtc_0 ; Branch if NObsf gFlags, Intervl_BIT ; Time for the to process next point
goto IntRet ; Returnrtc_0: btfss gFlags, WaitStart_BIT ; Are we waiting the process start for?
goto IntRet ; Branch if NObcf gFlags, WaitStart_BIT ; Clear waiting process flag
bsf gFlags, Process_BIT ; Set process in progress flag
goto IntRet ; ReturnTryADCInt: ; ADC interrupt
btfsc PIR1, ADCIF ; See if ADC is completed
goto AD_complete ; Branch if YESbtfsc PIR1, OVFIF ; Check if A/D counter overflow
goto AD_overflow ; Branch if YESbtfsc INTCON, TOIF ; See if the timer interrupt
goto TimerInterrupt ; Branch if YESbtfss PIR1, RCIF ; See if the PORTC interrupt
goto IntRet ; NO, return from interruptbsf STATUS, RP0 ; Disable PORTC interrupts
bcf PIE1, RCIE ;
bcf STATUS, RP0 ;
goto IntRet ; and return from interruptAD_overflow:
movlw 0xFF ; Indicate overflow result
clrf ADCAPL ;
clrf ADCAPH ;
AD_complete:
bsf ADCON0, ADRST ; Disable ADC
clrf ADTMRH ; Reset A/D timer
clrf ADTMRL ;
bcf PIR1, OVFIF ; Reset AD overflow interrupt flag
bcf PIR1, ADCIF ; Reset ADC completed interrupt flag
goto IntRet ; and returnTimerInterrupt:
btfsc RS232_BIT ; See if RS-232 Output is doing
goto TimIntRet ; Return if YESdecfsz ?TickCnt, f ; Bump the tick counter low byte
goto TimIntRet ; Return if NOT ZEROmovlw D'41' ; Set the low byte of tick counter
movwf ?TickCnt ;
bsf KEYPAD_BIT ; Set the flagincf ?DisplayCnt, f ; Bump display counter
btfss ?DisplayCnt, 3 ; See if time has to come
goto _tm0 ; Branch if NOclrf ?DisplayCnt ; Reset counter
bsf RTCREAD_BIT ; and set the flag
_tm0:
decfsz ?TickCnt+1, f ; Bump the tick counter high byte
goto TimIntRet ; Return if 5 sec. interval is not overincf ?TimeOut, f ; Update the time-out counter
btfsc ?TimeOut, 6 ; See if time-out state has to come
bsf gFlags, TimeOut_BIT ; Set the flag if YES
TimIntRet: ; Return from timer interrupt
bcf RS232Tx_BIT ; Reset RS-232 transmission flag
bcf INTCON, TOIF ; Clear interrupt flag
IntRet:
movfw PCHSave ; Restore PC high byte
movwf PCLATH ;
swapf StatSave, w ; Restore status
movwf STATUS ;
swapf WSave, f ; Restore W register
swapf WSave, w ;
retfie
E-mail: info@telesys.ru