PDA

View Full Version : Understanding Interrupts



kiwipiper
- 11th December 2007, 05:22
Greetings All

I have managed to get an interrupt working in my program but don't fully understand it all.
It is a very simple interrupt that activates when RB0 is taken low. Pretty much out of the PBP manual.

Here is the Code that Matters:

OPTION_REG = $7f
On Interrupt Goto myint ' Define interrupt handler
INTCON = $90 ' Enable RB0 interrupt

Disable ' No interrupts past this point
myint:
Stuff happens here ......
INTCON.1 = 0 ' Clear interrupt flag
Resume ' Return to main program
Enable

My Questions Are:

OPTION_REG = $7f was in the original example I used but it seems to work fine without it. What does this do? Do I need it?
How would I create a second Interrupt say when RB1 is taken low.
$90 is %10010000 therefore is the fourth 1 the bit that refers to RB0
When I clear the flag INTCON.1 = 0 what exactly is going on here.
If Resume Returns to the main program I take it Enable never gets run.

Can anyone help me understand Interrupts better.

Archangel
- 11th December 2007, 06:04
see this thread: http://www.picbasic.co.uk/forum/showthread.php?t=6444

kiwipiper
- 12th December 2007, 02:21
I am sorry to say the thread http://www.picbasic.co.uk/forum/showthread.php?t=6444 got me even more confused and I ended up with just a bunch more questions. However, the good news is that it made me search for more information. I ended up looking at this thread: http://www.picbasic.co.uk/forum/showthread.php?t=3251 and on to Darrel Taylors Wesite: http://darreltaylor.com/DT_INTS-18/home.html

So for others New to this and struggling with concept of interrupts my advice would be to check these two links out. I found it well documented and easier to understand than a bunch of other stuff I had struggled with for several nights. It certainly helped me heaps. My personal thanks goes out to Darrel Taylor

Darrel Taylor
- 12th December 2007, 23:54
Woohoo!

Newbus Interruptus.

One of the times you Like stopping what you were doing. :D
<br>

T.Jackson
- 13th December 2007, 00:25
lol ...

Well, they say that one of the best definitions for an interrupt is a telephone. If the phone's ringer was to be replaced with a LED -- you'd have to constantly glance at it once in a while to see if someone was calling you. Arguably, you'd never get any work done (certainly not as much) So, I guess this is comparable to continuously polling an input on a PIC. Here's a thought; could something be used to replace the ringer having an equal or better interrupt effect?

Darrel Taylor
- 13th December 2007, 02:39
Newbus Interruptus

There once was a newbie, that couldn't Interrupt.
Can't blame him, it's a hard thing to do.

He knows that he must, and with every thrust
his results have been proven un-true.

It's turmoil at home.
The thoughts of the Cost.
and the sleepless nights ahead.

He searches the forum,
and ignores the decorum, until his eyes were red.

He searches some more, it's really a bore,
and happens across a new thread.

It promises Interrupts, and sanity,
without all of the dread.

He tries with success,
and ceases distress,
and is ready to mount the new task.

Ha, and it worked. :)
<hr>

Uhh, you were saying something about telephones?

T.Jackson
- 13th December 2007, 03:19
Darrel,

Don't quit the pics :)

Darrel Taylor
- 13th December 2007, 04:03
hey,

There's a writers strike in california right now.

I gotta come up with it on my own. :o
<br>

sayzer
- 13th December 2007, 09:10
hey,

There's a writers strike in california right now.

I gotta come up with it on my own. :o
<br>

Darrel,

This is what you need:

www.poetry.com
I am already in semi-finals.

kiwipiper
- 14th December 2007, 01:11
Talking about LED's and Telephones and seeing you are all turning my thread into a comedy section I thought I would add to the mix ...

Reminded me of an incredibly funny segment from a comedy show I saw years ago...

It was highlighting an invention for deaf people so they would know when the phone rang. Basically they wore a device on the head which flashed an LED when their phone rang. Initially you thought what a great Idea until it actually flashed and the DEAF person wandered over and answered the phone. "HELLO, HELLO is anyone there ..... HELLO HELLO ..... HELLO ...."

On the same vain the interrupt for the blind sky diver, so that he knows when to pull the rip cord, is when the lead to the seeing eye dog goes slack.

Darrel Taylor
- 14th December 2007, 01:53
That's the Spirit!

Although I now have some disturbing mental images of how that ends up.

http://www.pbpgroup.com/files/splash.jpg