C8051F410/1/2/3
110 Rev. 1.1
12. Interrupt Handler
The C8051F41x family includes an extended interrupt system supporting a total of 18 interrupt sources
with two prior ity levels. Th e allocation of interrupt sour ces between on -chip peripher als and extern al input
pins varies according to the specific version of the device. Each interrupt source has one or more associ-
ated interrupt-pending flag(s) located in an SFR. When a peripheral or external source meets a valid inter-
rupt condition, the associated interrupt-pending flag is set to logic 1.
If interrupt s are ena bled for the sour ce, an interrupt request is gener ated when the interru pt-pending flag is
set. As soon as execution of the current instruction is complete, the CPU generates an LCALL to a prede-
termined address to begin executio n of an interrupt service ro utine (ISR). Each ISR must end with an RETI
instruction, which returns program execution to the next instruction that would have been executed if the
interrupt requ est had not occurred. If inter rupt s are not enabled, the inter rupt-pending fla g is ignored by the
hardware and program execution continues as normal. (The interrupt-pending flag is set to logic 1 regard-
less of the interrupt's enable/disable state.)
Each interrupt source can be individually enabled or disabled through the use of an associated interrupt
enable bit in the Interrupt Enable and Extended Interrupt Enable SFRs. However, interrupts must first be
globally enabled by setting the EA bit (IE.7) to logic 1 before the individual interrupt enables are recog-
nized. Setting the EA bit to logic 0 disables all interrupt sources regardless of the individual interrupt-
enable settings. Note that interrupts which occur when the EA bit is set to logic 0 will be held in a pending
state, and will not be serviced until the EA bit is set back to logic 1.
Some interrupt-pending flags ar e auto matically cleared by the hardware when the CPU vectors to the ISR.
However, most are not cle ared by the har dware a nd must b e clear ed by so ftware before retur ning fro m the
ISR. If an interrupt-pending flag remains set after the CPU completes the return-from-interrupt (RETI)
instruction, a new interrupt request will be generated immediately and the CPU will re-enter the ISR after
the completion of the next instruction.
12.1. MCU Interrupt Sources and Vectors
The MCUs support 18 interrupt sources. Software can simulate an interrupt by setting any interrupt-pend-
ing flag to logic 1. If interrupts are enabled for the flag, an interrupt request will be generated and the CPU
will vector to the ISR address associated with the interrupt-pending flag. MCU interrupt sources, associ-
ated vec tor addr esses, pr iority or der, and control bits are summarized in Table 12.1 on page 111. Refer to
the data sheet sec tion associated w ith a particular on-c hip peripheral f or informatio n regarding va lid inter -
rupt conditions for the peripheral and the behavior of its interrupt-pending flag(s).
12.2. Interrupt Priorities
Each interrupt source can be in dividua lly prog ra mmed to on e o f two p riority levels: lo w or h igh. A low prior-
ity interrupt service routine can be preempted by a high priority interrupt. A high priority inte rrupt cannot be
preempted. Each interrupt has an associated interrupt priority bit in an SFR (IP or EIP1) used to configure
its priori ty level. Low priority is th e default. If two interru pts are re cognized simult aneously, the interrupt with
the higher priority is serviced first. If both interrupts have the same priority level, a fixed priority order is
used to arbitrate, given in Table 12.1.
12.3. Interrupt Latency
Interrupt response time depends on the state of the CPU when the interrupt occurs. Pending interrupts are
sampled and priority decoded each system clock cycle. Therefore, the fastest possible response time is 7
system clock c ycles: 1 clock cycle to detect the interrupt, 1 clock cycle to execute a singl e instruction, and
5 clock cycl es t o co mpl ete t he L CALL to th e I SR. If an in ter rupt is pend ing when a RET I i s ex ecut ed, a sin -
gle instruction is executed before an LCALL is made to service the pending interrupt. Therefore, the maxi-
mum response time for an interrupt (when no other interrupt is currently being serviced or the new interrupt
is of greater priority) occurs when the CPU is performing an RETI instruction followed by a DIV as the next