PDA

View Full Version : interrupts - basic info needed



malc-c
- 28th December 2009, 16:40
Been reading up in interrupts and I'm still confused. From what I've read you can have several interrupts and they basically allow you to run something simultaneously whilst the main program continues from the point it was interrupted. Is this like the gosub command ?

I noted that it states that pause etc can delay the resume so what would be the difference in something like the following?


main:
pin goes high
pause 2000
pin goes low
display the time on an LCD

and


main:
interrupt one
display the time on LCD

interrupt one:
pin goes high
pause 2000
pin goes low
resume


in the second bit of code, would the pin be high whilst the time is shown on the LCD ? or would it wait for the pin to go low before resuming back to the main part of the program... ??

Sorry if this is very basic, but I've never written a routine with interrupts.

HenrikOlsson
- 28th December 2009, 17:47
Hi,

Generally speaking, when an interrupt occurs the main program execution stops, jumps to the interrupts service routine, executes the code that's in it and then jumps back and continues executing the main program where it left it. The main program does NOT continue WHILE the code in the interrupt service routine is executed.

So in your second program the the LCD would stop updating while the interrupt is serviced and then continue.

/Henrik.

malc-c
- 28th December 2009, 22:46
Thanks very much for the explanation.

So is an interrupt the same as gosub, in that it jumps out to a routine and then jumps back ?

HenrikOlsson
- 28th December 2009, 23:06
Yes it is.