Interrupts are something like, if you touch a hot stove, the sensor in your hand detects "something's wrong". That signal goes to a specific location in the brain and causes a muscle action to happen. You don't think about it - it just happens. No matter what you WERE doing before, your hand is going to yank back NOW! You'll then go back to what you were doing before you touched the hot stove.
More technically speaking, when a hardware interrupt is enabled, and one occurs, the hardware gates in the PIC direct the program pointer to a specific location in memory where the interrupt subroutine's address is stored. The program pointer gets the address of the interrupt service routine and then goes there to handle the interrupt. Once the interrupt handling routine (that you wrote) is done, then the program goes back to where it was based on what it was doing at the time of the interrupt.
Example: You were blinking an LED on Port A.0. All is well. In your program you configured the Port B.0 pin for interrupt on low-to-high transition and enable the Port B.0 interrupt. Then you pushed a button that connects 5v to Port B.0. The blink portion of the program is stopped, and the chip's internal program pointer goes to the interrupt location in memory and looks for the address of your interrupt handler, and goes there. Once it gets to the end of that routine, then action resumes in the main program (blinking the A.0 LED) where it left off before the interrupt occured.
You can do this via two methods - PBP or DT INTS. It really depends on how fast you want to handle the interrupt and how much you want to "do it the right way", I guess. In other languages and chips, I've always used hardware interrupts and prefer to handle them as fast as possible and with as little impact on the running program as possible. Often times the interrupt is something that's just plain boring or bothersome like an input character from a USART, a counter rolling over, a timer rollover, odometer tic, etc. Nothing you really want to redirect the main program over, but something that still needs to be addressed and then move on back to what you were doing before. Interrupts using DT INTS is the fastest way, and probably (technically) the right way to handle PIC interrupts while using PBP as your language. I strongly suggest learning more about interrupts at the hardware level (RTFM) before you attempt DT INTS. While Dave's documentation is good, it assumes you know what/how/why interrupt in the first place. Not a good place for a newbie to go off exploring without some guidance.
Hope this helped,
rswain
Last edited by rswain; - 25th March 2009 at 20:37.
OK lets beat this subject into shim stock . . . INTERRUPTS are TRIGGERED by hardware events, They are handled by software. Assembly will start working on the interrupt within 2 to 4 cycles of the Oscillater. PBP On Interrupt, puts a pointer on the stack, like it does with a subroutine, and executes it right after it finishes what it is doing.
Consider this:In the example above ASM interrupts will shut the motor off right now, PBP might have you wait 59 secondsCode:start: on interrupt goto Emergency<font color=red><b>_</b></font color>stop ':D thanks mister_e main: PortB.3 = 1 ' motor runs for 1 minute, stops for 1 minute pause 60000 PortB.1 = 0 Pause 60000 goto main Emergency_Stop: PortB.3 = 0 sleep end
Last edited by Archangel; - 26th March 2009 at 06:26.
If you do not believe in MAGIC, Consider how currency has value simply by printing it, and is then traded for real assets.
.
Gold is the money of kings, silver is the money of gentlemen, barter is the money of peasants - but debt is the money of slaves
.
There simply is no "Happy Spam" If you do it you will disappear from this forum.
and in the example above, there's an underscore missing![]()
Steve
It's not a bug, it's a random feature.
There's no problem, only learning opportunities.
Big thanks to you all
-Dan-
Jerson
jmgelba
Joe S. --- Oh those funny days N. Khouroutchouv and others
rswain
mister_e
-------------------
Greetings from Algeria.
Question:
Did anyone manage to get a working PicBasic pro + Microstudio + wine under Debian GNU/linux_lenny.
Thanks in advance.
Bookmarks