I've set up a very basic program to experiment with interrupts on a 16F84 (ive basically just used the example interrupt code from the pbp manual)
This main program should loop forever until RB0/INT goes high (via a pushbutton), and the interrupt routine should trigger and turn on the LED, and then go back to the endless loop in the main program.
However, when I press the button, the LED comes on for about 2 seconds and then turns off again. So i checked to see if it was resetting by putting code at the beginning of the program that makes the LED flash on and off a few times.
Sure enough, when i pressed the button, the LED came on for 2 seconds and then flashed, so the program was reset for some reason. It even resets if i pull out the oscillator after pressing the button. Now this seems to point me towards thinking that the watchdog timer is going off, but i dont know why it would.
Code:DEFINE OSC 10 ' Oscillator = 10MHz define INTHAND int_handler ' Define interrupt handler INTEDG VAR OPTION_REG.6 ' RB0 Interrupt edge select: 1=Rising Edge 0=Falling Edge INTF VAR INTCON.1 ' RB0 Interrupt flag INTE VAR INTCON.4 ' RB0 Interrupt enable GIE VAR INTCON.7 ' Global interrup enable LED var PORTB.1 ' LED on RB1 wsave var byte $20 system ' Variable for saving W Register on Interrupt ssave var byte bank0 system ' Variable for saving STATUS Register on Interrupt psave var byte bank0 system ' Variable for saving PCLATH Register on Interrupt fsave var byte bank0 system ' Variable for saving FSR Register on Interrupt HIGH LED ' Flash LED Twice pause 50 low led pause 50 high led pause 50 low led INTEDG=1 ' RB0 Interrupt to Trigger on Rising Edge INTF=0 ' Enable RB0 Interrupt INTE=1 ' Enable RB0 Interrupt GIE=1 ' Global Interrupt Enable loop: Goto loop ' Endless Loop '-----------------------------------------------------------------------------' ' Interrupt Handler ' '-----------------------------------------------------------------------------' asm int_handler ; Save Resisters ; movwf wsave ; Save W Register into wsave swapf STATUS,W ; Save STATUS Register into ssave clrf STATUS movwf ssave movf PCLATH,W ; Save PCLATH Register into psave movwf psave movf FSR,W ; Save FSR Register into fsave movwf fsave ; Interrupt Code ; bsf _LED ; Turn on LED ; Restore Resisters ; movf fsave,W ; Restore FSR Resister movwf FSR movf psave,W ; Restore PCLATH Resister movwf PCLATH swapf ssave,W ; Restore STATUS Resister movwf STATUS swapf wsave,F ; Restore W Resister swapf wsave,W retfie endasm
Bookmarks