The basic interrupt routine you have worked with
SOMETHING...Code:DISABLE TLOOP: 'DO SOMETHING INTCON.2=0 RESUME ENABLE
I = I + 1
IF ??? THEN
???
RESET COUNTER
ENDIF
Tick Tock...![]()
The basic interrupt routine you have worked with
SOMETHING...Code:DISABLE TLOOP: 'DO SOMETHING INTCON.2=0 RESUME ENABLE
I = I + 1
IF ??? THEN
???
RESET COUNTER
ENDIF
Tick Tock...![]()
Dave
Always wear safety glasses while programming.
That's what I was trying to fit in.Code:DISABLE TLOOP: IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0 IF I<=100 GOTO MAIN IF I =100 GOTO TOG tog:TOGGLE GPIO.2 RESUME: ENABLE
Blimmey, it's nearly Friday already
Am I close-ish.
Dave
Close-ish...
IF INTCON.2=1
is not needed in the interrupt routine, that is what send the code there in the first place.
The rest might work.
Does it??
Dave
Always wear safety glasses while programming.
Mmmm.
I was trying to use then reset IF INTCON.2=1 to increment count on 'I' the VAR.
I'll sleep on it (I hope it doesn't keep me awake thinking).Code:IF INTCON.2=1 THEN I = I + 1 :INTCON.2=0
Dave
Something...
I = I + 1
if ??? Then
???
I = 0 'reset counter
endif
Dave
Always wear safety glasses while programming.
Correct. But remember that if/when you start adding more interrupt sources you need to determine which one it was that tripped so checking the interrupt flag is probably good practice. But as have been said, it's not strictly needed in this case.IF INTCON.2=1
is not needed in the interrupt routine, that is what send the code there in the first place.
You seem to have a GOTO Main inside the ISR - you can do that but it is probably not a good idea as it will restart from the beginning of the program and not where it got interrupted. This MAY not be a problem in THIS particular program but can cause some interesting results so - try not to do that.
Have a look at this:
/Henrik.Code:DISABLE TLOOP: IF INTCON.2 = 1 THEN 'TMR0 Interrupt? I = I + 1 'Increment counter IF I = 100 THEN 'Has it reached 100? TOGGLE GPIO.2 'If so, toggle LED... I = 0 '...and reset counter ENDIF INTCON.2 = 0 'Reset interrupt flag ENDIF RESUME 'back to work. ENABLE
Well once again I've learned a lot of things, thanks as ever.
In the UK there's a famous comedy sketch where a musician says "I was playing all the right notes
but not necessarily in the right order".
I was a little (ok a lot) like that in this last exercise. I had written down I = 0 to reset the counter, I knew
I had to do that which is something and I'd figured I = I + 1 to add to / increment the counter, so not all bad.
Henrik highlighted within the program:
I guess that's because as mackrackit pointed out to me that for the program to be there the INTERRUPTCode:INTCON.2 = 1 THEN 'TMR0 Interrupt?
must have already occured?
10/10 for you guys.Code:ANSEL = %00000000 'Disable analog select so ports work as digital i/o CMCON0 = %00000111 'Disable analog comparators TRISIO = %11111110 'TRISIO.0 set as OUTPUT GPIO = %00000000 'All bits set LOW INTCON.5 = 1 'ENABLE TMR0 OPTION_REG = %10000101 '16BIT 1:64 PRESCALE ON INTERRUPT GOTO TLOOP 'ON INTERRUPT GOTO the INTERRUPT handler LABEL 'TLOOP' i var byte 'Set I as a VARIABLE BYTE Main: Not_pressed: PAUSE 25 'Leave 25mili_sec for a button press to occur. if GPIO.5 = 1 THEN GOTO Not_pressed 'Keep waiting for +0v button press on GPIO.5 IF GPIO.5 = 0 THEN goto LED 'Button has been pressed move to LABEL LED: LED: TOGGLE GPIO.0 'Change state of GPIO.0 pin GOTO Not_pressed 'Start again DISABLE 'Disable INTERRUPT in handler TLOOP: IF INTCON.2 = 1 THEN 'TMR0 Interrupt? I = I + 1 'Increment counter IF I = 100 THEN 'Has it reached 100? TOGGLE GPIO.2 'If so, toggle LED... I = 0 '...and reset counter ENDIF INTCON.2 = 0 'Reset interrupt flag ENDIF RESUME:ENABLE 'ENABLE INTERRUPT in handler start prog again
Dave (not clever just persistent).
Last edited by LEDave; - 26th March 2010 at 21:02.
Bookmarks