Email: Password: Remember Me | Create Account (Free)

Back to Subject List

Old thread has been locked -- no new posts accepted in this thread
???
07/14/01 15:14
Read: times


 
#13209 - RE: Do interupts use flags?
Martin,

Suppose the interrupts are enabled.
When an interrupt occurs, the current program counter (PC) is pushed on the stack, and a new value is automatically loaded into PC, which is in effect a jump to a particular location. The exact location depends on the interrupt source (see specs of your processor).

So far so good. The main program is interrupted and your interrupt routine is running. The first things to do now is to save all affected registers on the stack. You may concider switching to a different register bank too. This avoids disturbing your main program's data.
Then you can actually execute your interrupt routine.
Now you must clear the interrupt source flag (is different per interrupt source, see specs). If you don't your interrupt will be called again once it is finished, like Daniel described.
Upon exit you must restore all saved registers again, in order to put the processor in the exact same state as it was when you entered the interrupt routine. Then you should finish with the RETI instruction, which POPs the return address from stack, and your main program gets control again.

To make it more complicated there are interrupt sources that share one interrupt vector, like Serial In and Serial Out. When you enter the interrupt routine you can examine both flags to see which one (or maybe both) sources triggered the interrupt. Don't forget to clear the approriate flag, otherwise your interrupt routine will be called again once it finishes.

The interrupt vector address is simply a dedicated address in your program memory (addresses 0003h, 000Bh, 0013h, 001Bh, etc.) You can put an 8 byte long program there, otherwise you run into the next interrupt source's space. Usually a JMP instruction is placed on those vector addresses to get more room to execute the real interrupt routine.

Happy programming

List of 15 messages in thread
TopicAuthorDate
Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      
RE: Do interupts use flags?            01/01/70 00:00      

Back to Subject List