Specifications

Chapter 2 - Microcontroller PIC16F84
External interrupt on RB0/INT pin is triggered by rising signal edge (if bit INTEDG=1 in OPTION<6>
register), or falling edge (if INTEDG=0). When correct signal appears on INT pin, INTF bit is set in
INTCON register. INTF bit (INTCON<1>) must be reset in interrupt routine, so that interrupt wouldn't
occur again while going back to the main program. This is an important part of the program which
programmer must not forget, or program will constantly go into interrupt routine. Interrupt can be
turned off by resetting INTE control bit (INTCON<4>).
Interrupt during a TMR0 counter overflow
Overflow of TMR0 counter (from FFh to 00h) will set T0IF (INTCON<2>) bit. This is very important
interrupt because many real problems can be solved using this interrupt. One of the examples is time
measurement. If we know how much time counter needs in order to complete one cycle from 00h to
FFh, then a number of interrupts multiplied by that amount of time will yield the total of elapsed
time. In interrupt routine some variable would be incremented in RAM memory, value of that variable
multiplied by the amount of time the counter needs to count through a whole cycle, would yield total
elapsed time. Interrupt can be turned on/off by setting/resetting T0IE (INTCON<5>) bit.
Interrupt during a change on pins 4, 5, 6 and 7 of port B
Change of input signal on PORTB <7:4> sets RBIF (INTCON<0>) bit. Four pins RB7, RB6, RB5 and
RB4 of port B, can trigger an interrupt which occurs when status on them changes from logic one to
logic zero, or vice versa. For pins to be sensitive to this change, they must be defined as input. If any
one of them is defined as output, interrupt will not be generated at the change of status. If they are
defined as input, their current state is compared to the old value which was stored at the last reading
from port B. Interrupt can be turned on/off by setting/resetting RBIE bit in INTCON register.
Interrupt upon finishing write-subroutine to EEPROM
This interrupt is of practical nature only. Since writing to one EEPROM location takes about 10ms
(which is a long time in the notion of a microcontroller), it doesn't pay off to a microcontroller to wait
for writing to end. Thus interrupt mechanism is added which allows the microcontroller to continue
executing the main program, while writing in EEPROM is being done in the background. When writing
is completed, interrupt informs the microcontroller that writing has ended. EEIF bit, through which
this informing is done, is found in EECON1 register. Occurrence of an interrupt can be disabled by
resetting the EEIE bit in INTCON register.
Interrupt initialization
In order to use an interrupt mechanism of a microcontroller, some preparatory tasks need to be
performed. These procedures are in short called "initialization". By initialization we define to what
interrupts the microcontroller will respond, and which ones it will ignore. If we do not set the bit that
allows a certain interrupt, program will not execute an interrupt subprogram. Through this we can
obtain control over interrupt occurrence, which is very useful.
The above example shows initialization of external interrupt on RB0 pin of a microcontroller. Where
we see one being set, that means that interrupt is enabled. Occurrence of other interrupts is not
allowed, and all interrupts together are disallowed until GIE bit is keeping to one.
The following example shows a typical way of handling interrupts. PIC16F84 has only one location
where the address of an interrupt subprogram is stored. This means that first we need to detect
which interrupt is at hand (if more than one interrupt source is available), and then we can execute
that part of a program which refers to that interrupt.
http://www.mikroelektronika.co.yu/english/product/books/PICbook/2_07Poglavlje.htm (6 of 7) [4/2/2003 16:17:55]