Microchip Technology SW006022-2N 데이터 시트
Interrupts
2012 Microchip Technology Inc.
DS52071B-page 185
11.8.1.3
APPLICATION EXAMPLE
The following example highlights some of the points discussed in this section:
void
__
attribute
_ _
((interrupt))
HigherPriorityInterrupt(void) {
/* User Code Here */
LATGbits.LATG15 = 1; /* Set LATG bit 15 */
IPC0bits.INT0IP = 2; /* Set Interrupt 0
priority (multiple
bits involved) to 2 */
}
int main(void) {
/* More User Code */
LATGbits.LATG10 ^= 1; /* Potential HAZARD -
First reads LATG into a W reg,
implements XOR operation,
then writes result to LATG */
LATG = 0x1238; /* No problem, this is a write
only assignment operation */
LATGbits.LATG5 = 1; /* No problem likely,
this is an assignment of a
single bit and will use a single
instruction bit set operation */
LATGbits.LATG2 = 0; /* No problem likely,
single instruction bit clear
operation probably used */
LATG += 0x0001; /* Potential HAZARD -
First reads LATG into a W reg,
implements add operation,
then writes result to LATG */
IPC0bits.T1IP = 5; /* HAZARD -
Assigning a multiple bitfield
can generate a multiple
instruction sequence */
}
A statement can be protected from interrupt using the INTERRUPT_PROTECT macro
provided above. For this example:
provided above. For this example:
INTERRUPT_PROTECT(LATGbits.LATG15 ^= 1); /* Not interruptible by
level 1-7 interrupt
requests and safe
at any optimization
level */