Digital I/O Operation
370
SLAU367P – October 2012 – Revised April 2020
Copyright © 2012–2020, Texas Instruments Incorporated
Digital I/O
Only transitions, not static levels, cause interrupts. If any PxIFG flag becomes set during a Px interrupt
service routine or is set after the RETI instruction of a Px interrupt service routine is executed, the set
PxIFG flag generates another interrupt. This ensures that each transition is acknowledged.
NOTE:
PxIFG flags when changing PxOUT, PxDIR, or PxREN
Writing to PxOUT, PxDIR, or PxREN can result in setting the corresponding PxIFG flags.
Any access (read or write) of the lower byte of the PxIV register, either word or byte access, automatically
resets the highest pending interrupt flag. If another interrupt flag is set, another interrupt is immediately
generated after servicing the initial interrupt.
For example, assume that
.0 has the highest priority. If the P1IFG.0 and P1IFG.2 flags are set when
the interrupt service routine accesses the
P1IV
register, P1IFG.0 is reset automatically. After the RETI
instruction of the interrupt service routine is executed, the P1IFG.2 generates another interrupt.
12.2.6.1 P1IV Software Example
The following software example shows the recommended use of
P1IV
and the handling overhead. The
P1IV value is added to the PC to automatically jump to the appropriate routine. The code to handle any
other PxIV register is similar.
The numbers at the right margin show the number of CPU cycles that are required for each instruction.
The software overhead for different interrupt sources includes interrupt latency and return-from-interrupt
cycles but not the task handling itself.
;Interrupt handler for P1
Cycles
P1_HND
...
; Interrupt latency
6
ADD
&P1IV,PC
; Add offset to Jump table
3
RETI
; Vector
0: No interrupt
5
JMP
P1_0_HND
; Vector
2: Port 1 bit 0
2
JMP
P1_1_HND
; Vector
4: Port 1 bit 1
2
JMP
P1_2_HND
; Vector
6: Port 1 bit 2
2
JMP
P1_3_HND
; Vector
8: Port 1 bit 3
2
JMP
P1_4_HND
; Vector 10: Port 1 bit 4
2
JMP
P1_5_HND
; Vector 12: Port 1 bit 5
2
JMP
P1_6_HND
; Vector 14: Port 1 bit 6
2
JMP
P1_7_HND
; Vector 16: Port 1 bit 7
2
P1_7_HND
; Vector 16: Port 1 bit 7
...
; Task starts here
RETI
; Back to main program
5
P1_6_HND
; Vector 14: Port 1 bit 6
...
; Task starts here
RETI
; Back to main program
5
P1_5_HND
; Vector 12: Port 1 bit 5
...
; Task starts here
RETI
; Back to main program
5
P1_4_HND
; Vector 10: Port 1 bit 4
...
; Task starts here
RETI
; Back to main program
5
P1_3_HND
; Vector 8: Port 1 bit 3
...
; Task starts here
RETI
; Back to main program
5
P1_2_HND
; Vector 6: Port 1 bit 2
...
; Task starts here
RETI
; Back to main program
5
P1_1_HND
; Vector 4: Port 1 bit 1
...
; Task starts here