-
Help with interupts
I am just starting to mess with interupts. Just to get a feel for how they work, I have the following code.
Code:
LED VAR PORTD.0
PB VAR PORTB.0
TONE VAR PORTC.3
CTONESET VAR BIT
loop1 Var BYTE
TRISD = %00000000
TRISB = %00000001
INTCON = %10010000
DEFINE OSC 10
ON INTERRUPT Goto MyInt
INTCON = $90
mainloop:
if PB = 1 then
IF CTONESET=1 then
FOR loop1 = 0 to 500
pause 1
Next loop1
gosub CTone
LED = 0
For loop1 = 0 to 1000
pause 1
next loop1
endif
endif
goto mainloop
CTONE:
Sound Tone,[88,7,91,7,99,7]
CToneSet=0
return
disable
Myint:
led = 1
CToneSet = 1
INTCON.1=0
resume
end
What I expected to happen was when I push the button on RB0, the led would light. when I let it go I wanted it to play a tone and then turn off the led. What I get is I push the button, and the LED is off. I release the button, the LED lights, the tone plays, and the LED turns off. What am I doing wrong. I know it is something simple.
Thanks!
-
Re: Help with interupts
Not knowing what chip you are using... Look for "Interrupt on rising edge", it might be in INTCON2 .
-
Re: Help with interupts
-
Re: Help with interupts
OK INTCON2 fixed the problem. Thanks.
NowI think really need to impliment an interupt on a timer. I need to do several things at ones.
1) Check condition on a multiple pins(Buttons) and do something on other pins(LED) based on what the button status is.
2) Keep a count of how long since an action occured. (I.E. I wnat to run a sub routine every X Minutes
-
Re: Help with interupts
ON INTERRUPT works fine if you do not care if the event is not acted upon instantly. ON INTERRUPT is pretty easy to use.
If a interrupt is time sensitive you will want to use ASM interrupts, there is an example in the manual, but ASM interrupts can be tricky.
The best of both, easy and fast are brought together here.
http://darreltaylor.com/DT_INTS-18/home.html
You will still need to have your data sheet open...:lemo: