Quote Originally Posted by skimask View Post
General code flow when using ON_INTERRUPT's...(you mileage may vary, others do it other ways, I do it this way)...

1) resetplaceholder: 'just a placeholder

2) ------DEFINEs needed thru the program

3) DISABLE 'need to disable interrupts while actually processing an interrupt

4) CLEAR

5) ------any eeprom data, variable definitions, etc.

6) ------macro's you might be using

7) startupholder: goto skipsubs 'skip over all the commonly used subroutines

8) ON INTERRUPT GOTO INTHANDLER

9) INTHANDLER: 'process your interrupts.

10) 'check the interrupt bits, if the interrupt you want is active, reset the bit and process it

11) INTFINISH: 'I usually recheck the interrupt sources. If one of them tripped while I was processing a previous interrupt, I go back and re-process the interrupt

12) INTRESUME: RESUME 'resume AFTER you've processed the interrupt

13) 'commonly used subroutines start below here

14) commonly_used_sub_1: 'do something here and return from it

15) ..........

16) 'end of commonly used subroutines, skipsubs block for setting up registers, lcd, whatever

17) skipsubs: 'set up the PIC as required

18) mainloop: 'the main program runs here waiting to get interrupted

19) ------------more program stuffed in here.........

20) goto mainloop

21) END

hello,
i wanted to test an interrupt in a simple small code , i found a code on the internet and modified it and got this:
@ DEVICE INTRC_OSC, LVP_OFF, WDT_OFF, MCLR_OFF

DEFINE OSC 4

OSCCON=%01101000 ' INTRC = 8MHz
ANSEL=%00000000
CMCON=%00000111


OPTION_REG.6=1 'Trigger on rising edge
INTCON = %10010000 'Enable INTE
INTCON.1 = 0 'Clear RB0/INT External Interrupt Flag bit

On Interrupt Goto UpdateCounter

PORTB=0 ' PORTBs are outputs
Pause 500 ' Wait for startup
'LOW PORTB.6

loop:
low portb.6
HIGH PORTB.5
Pause 2000 ' Wait 2 second

low portb.6
LOW PORTB.5
Pause 2000 ' Wait 2 second
Goto loop ' Do it forever

Disable
UpdateCounter:
LOW PORTB.5
HIGH PORTB.6
pause 500
low portb.5
LOW PORTB.6
pause 500

INTCON.1=0 're-enable interrupts

resume
ENABLE
GOTO loop

END


the code works, but the interrupt routine doesn't work, doesn t light the led connected to pin portb.6.
I mean when the portb.0 is connected to ground the led connected to portb.5 blinks as soon as i connect the portb.0 to +5v the portb.5 stops to blink and nothing happens to portb.6 led.
can you help me on that please???
how can I use a digital signal to activate the interrupt for example, with an if statement??

if portb.0 = 1 , the interrupt is activated and the program jumps to the int subroutine and if portb.0 = 0 the program comes back to the main loop???????

thank you