Specifications
mikroElektronika | Free Online Book | PIC Microcontrollers | Appendix B: Examples
Pay attention to a few details:
● Even though it is unnecessary in this case, the contents of the most important registers (W, STATUS and PCLATH)
must be saved at the beginning of the interrupt routine;
● Interrupt causes the appropriate flag bit to be automatically set and the GIE bit to be automatically cleared. At the
end of the interrupt routine, do not forget to return these bits to the state they had prior to the interrupt
occurring; and
● At the end of the interrupt rutine, important registers should be given the original content.
Example 4:
;********************** Header **********************************************
;**************** DEFINING VARIABLES ****************************************
cblock 0x20 ; Block of variables starts at address 20h
w_temp ; Variable at address 20h
pclath_temp ; Variable at address 21h
status_temp ; Variable at address 22h
endc
;************************ START OF PROGRAM **********************************
org 0x0000 ; Address of the first program instruction
goto main ; Go to label "main"
;************************ INTERRUPT ROUTINE *********************************
org 0x0004 ; Interrupt vector
movwf w_temp ; Saves value in register W
movf STATUS ; Saves value in register STATUS
movwf status_temp
movf PCLATH ; Saves value in register PCLATH
http://www.mikroe.com/en/books/picmcubook/appb/ (25 of 54)5/3/2009 11:36:02 AM