;Anthony Rogers
;Oct 19th, 05
;TgglIntF630 - Interrupt Demo
list p=16F630 ; list directive to define processor
#include <p16F630.inc> ; processor specific variable definitions
__CONFIG _CP_OFF & _CPD_OFF & _BODEN_OFF & _MCLRE_OFF &
_WDT_OFF & _PWRTE_ON & _INTRC_OSC_NOCLKOUT
INT_VAR UDATA_SHR 0x20
w_temp RES 1 ; variable used for context saving
status_temp RES 1 ; variable used for context saving
;**********************************************************************
RESET_VECTOR CODE 0x000 ; processor reset vector
goto main ; go to beginning of program
INT_VECTOR CODE 0x004 ; interrupt vector location
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
bcf INTCON, INTF ;clear interrupt
incf PORTC, f
movf status_temp,w ; retrieve copy of STATUS register
movwf STATUS ; restore pre-isr STATUS register contents
swapf w_temp,f
swapf w_temp,w ; restore pre-isr W register contents
retfie ; return from interrupt
main
call 0x3FF ; retrieve factory calibration value
bsf STATUS,RP0 ; set file register bank to 1
movwf OSCCAL ; update register with factory cal value
movlw 0x00 ; initialize TRISC to output
movwf TRISC
movlw b'00000100' ; set PORTA, bit 3 (aka PORTA<3>) to input
movwf TRISA
bcf STATUS,RP0 ; set file register bank to 0
movlw b'00000111' ; setting CMCON<2:0> to 1 puts the comparator module in
movwf CMCON ; "off" mode, allowing us to use PORTA<2> as digital input
bsf INTCON, INTE ; enable External Interrupt
bsf INTCON, GIE ; enable interrupts globally
loop
goto loop ; loop & wait...
END ; directive 'end of program'