Specifications

Chapter 2 - Microcontroller PIC16F84
Generally speaking, each interrupt source has two bits joined to it. One enables interrupts, and the
other detects when interrupts occur. There is one common bit called GIE which can be used to
disallow or enable all interrupts simultaneously. This bit is very useful when writing a program
because it allows for all interrupts to be disabled for a period of time, so that execution of some
important part of a program would not be interrupted. When instruction which resets GIE bit was
executed (GIE=0, all interrupts disallowed), any interrupt that remained unsolved should be ignored.
Interrupts which remained unsolved and were ignored, are processed when GIE bit (GIE=1, all
interrupts allowed) would be cleared. When interrupt was answered, GIE bit was cleared so that any
additional interrupts would be disabled, return address was pushed onto stack and address 0004h
was written in program counter - only after this does replying to an interrupt begin! After interrupt is
processed, bit whose setting caused an interrupt must be cleared, or interrupt routine would
automatically be processed over again during a return to the main program.
Keeping the contents of important registers
Only return value of program counter is stored on a stack during an interrupt (by return value of
program counter we mean the address of the instruction which was to be executed, but wasn't
because interrupt occured). Keeping only the value of program counter is often not enough. Some
registers which are already in use in the main program can also be in use in interrupt routine. If they
were not retained, main program would during a return from an interrupt routine get completely
different values in those registers, which would cause an error in the program. One example for such
a case is contents of the work register W. If we suppose that main program was using work register
W for some of its operations, and if it had stored in it some value that's important for the following
instruction, then an interrupt which occurs before that instruction would change the value of work
register W which would directly be influenced the main program.
Procedure of recording important registers before going to an interrupt routine is called PUSH, while
the procedure which brings recorded values back, is called POP. PUSH and POP are instructions with
some other microcontrollers (Intel), but are so widely accepted that a whole operation is named after
them. PIC16F84 does not have instructions like PUSH and POP, and they have to be programmed.
http://www.mikroelektronika.co.yu/english/product/books/PICbook/2_07Poglavlje.htm (3 of 7) [4/2/2003 16:17:55]