回來時,我正在寫一些彙編代碼PIC16F628A,發現如下問題時中斷:PIC:禁止從ISR
的GIE(全局中斷使能位)當ISR程序被調用時自動清零。然後,當ISR例程返回時,該位會自動重新設置。
我希望中斷在ISR例程返回時永久禁用,我不希望GIE被重置,但無論如何重置。
下面是一些示例代碼:
LIST p=16F628A
#INCLUDE <P16F628A.INC>
__CONFIG _LP_OSC & _WDT_OFF & _PWRTE_OFF & _BODEN_OFF & _INTRC_OSC_NOCLKOUT & _MCLRE_OFF
CONTROL EQU 0X20 ; A general purpose register used to control a loop
CAN_GO_ON EQU 0 ; A flag bit at register CONTROL
ORG 00
goto start
ORG 04
goto isr
ORG 10
start
bsf STATUS, RP0 ; Selects bank 1
movlw 0xFF ; Set all PORTB pins as input
movwf TRISB
bcf STATUS,RP0 ; Selects bank 0
movlw 0x08 ; Enables only PORTB<4:7> change interrupts
movwf INTCON ; GIE is cleared for now.
; ... later in the code ...
wait_for_interrupt_to_happen
bsf INTCON, GIE ; Enable interrupts. INTCON now reads 0x88
someloop ; This loop will go on and on until and interrupt occurs
nop ; and the ISR set the flag CAN_GO_ON
btfsc CONTROL, CAN_GO_ON
goto resume_program ; The isr returned, GIE is set. I don't want another interrupt to
; happen now. But if PORTB<4:7> changes now, isr will be called
; again before I have the chance to clear GIE and disable interrupts. :(
goto someloop
resume_program
bcf INTCON, GIE ; I don't want more interrrupts to happen, so I clear GIE.
; INTCON now reads 0x08
; ...
; ...
; ...
isr
nop ; An interrupt has ocurred. GIE is automatically disabled here.
; INTCON reads 0x09
bsf CONTROL, CAN_GO_ON ; flag CAN_GO_ON is set so the program can break from the loop
; and resume execution
bcf INTCON, RBIF ; clear the PORTB change interrupt flag. INTCON now reads 0x08
retfie ; after retfie, GIE is automatically reset, and INTCON will read 0x88
end
如何禁用從一件事中斷的ISR中斷不會再次啓用?
在此先感謝您的幫助。
剛剛得到了這個。非常感謝! – fhpriamo