С PIC18 не работал, есть только для PIC16 только. Взял "as is", не обессудьте.
(«Телесистемы»: Конференция «Микроконтроллеры и их применение»)

миниатюрный аудио-видеорекордер mAVR

Отправлено Bill 14 августа 2004 г. 15:55
В ответ на: Помогите в освоении PIC18Fxx2: Не можем заставить работать контроллер по прерываниям. отправлено Sem 14 августа 2004 г. 15:34


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 NO

RTCInterrupt: ; 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 NO

bsf gFlags, Intervl_BIT ; Time for the to process next point
goto IntRet ; Return

rtc_0: btfss gFlags, WaitStart_BIT ; Are we waiting the process start for?
goto IntRet ; Branch if NO

bcf gFlags, WaitStart_BIT ; Clear waiting process flag
bsf gFlags, Process_BIT ; Set process in progress flag
goto IntRet ; Return

TryADCInt: ; ADC interrupt
btfsc PIR1, ADCIF ; See if ADC is completed
goto AD_complete ; Branch if YES

btfsc PIR1, OVFIF ; Check if A/D counter overflow
goto AD_overflow ; Branch if YES

btfsc INTCON, TOIF ; See if the timer interrupt
goto TimerInterrupt ; Branch if YES

btfss PIR1, RCIF ; See if the PORTC interrupt
goto IntRet ; NO, return from interrupt

bsf STATUS, RP0 ; Disable PORTC interrupts
bcf PIE1, RCIE ;
bcf STATUS, RP0 ;
goto IntRet ; and return from interrupt

AD_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 return

TimerInterrupt:
btfsc RS232_BIT ; See if RS-232 Output is doing
goto TimIntRet ; Return if YES

decfsz ?TickCnt, f ; Bump the tick counter low byte
goto TimIntRet ; Return if NOT ZERO

movlw D'41' ; Set the low byte of tick counter
movwf ?TickCnt ;
bsf KEYPAD_BIT ; Set the flag

incf ?DisplayCnt, f ; Bump display counter
btfss ?DisplayCnt, 3 ; See if time has to come
goto _tm0 ; Branch if NO

clrf ?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 over

incf ?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