Interrupts are mechanisms inside of a microcontroller that allow responding to some event immediately after its detection. Events could be internal (timer overrun, end of AD conversion) or external (character receiving
over serial connection, pin state change). When interrupt occurs program execution is interrupted (hence the name) by jumping to part of the program that is called interrupt routine. Upon ending of that routine program continues from place in program where interruption took place. Interrupt controller makes hardware interrupt detection, program flow interruption by jumping to interrupt routine, as well as returning to interruption point from the routine. These operations are executed in several steps:
- When event that triggers interruption takes place, interrupt controller stores interrupt type.
- End of current instruction is awaited.
- If interrupt is allowed and if global interrupt permit is set to 0ne (GIE = 1), interrupt processing begins. For later continuing of instructions execution, stack holds values of PCH, PCL and F registers.
- New interrupt occurrence is disabled by setting values of register F to zero (GIE = 0).
- Program counter is set to address of interrupt routine, which is same as interrupt type, after which execution jumps to interrupt routine address.
- Program executes interrupt routine instructions.
- When it gets to instruction reti, which marks return from main program, values of F register are restored from stack, and program counter is reset to old value before interrupt occurred.
Register PRTxIF is used as indication of GPIO interrupt on certain port, while PRTxIC1and PRTxIC0 are
appropriate control registers. Every interrupt type can be masked or deleted, which is done with help of INT_MSK and INT_CLR registers, which will be discussed in more detail in examples part.
No comments:
Post a Comment