Professional Documents
Culture Documents
4.2 PORTB and the TRISB Register This interrupt can wake the device from Sleep. The
user, in the Interrupt Service Routine, can clear the
PORTB is an 8-bit wide, bidirectional port. The corre- interrupt in the following manner:
sponding data direction register is TRISB. Setting a
TRISB bit (= 1) will make the corresponding PORTB a) Any read or write of PORTB. This will end the
pin an input (i.e., put the corresponding output driver in mismatch condition.
a High-Impedance mode). Clearing a TRISB bit (= 0) b) Clear flag bit RBIF.
will make the corresponding PORTB pin an output (i.e., A mismatch condition will continue to set flag bit RBIF.
put the contents of the output latch on the selected pin). Reading PORTB will end the mismatch condition and
Three pins of PORTB are multiplexed with the In-Circuit allow flag bit RBIF to be cleared.
Debugger and Low-Voltage Programming function: The interrupt-on-change feature is recommended for
RB3/PGM, RB6/PGC and RB7/PGD. The alternate wake-up on key depression operation and operations
functions of these pins are described in Section 14.0 where PORTB is only used for the interrupt-on-change
“Special Features of the CPU”. feature. Polling of PORTB is not recommended while
Each of the PORTB pins has a weak internal pull-up. A using the interrupt-on-change feature.
single control bit can turn on all the pull-ups. This is per- This interrupt-on-mismatch feature, together with soft-
formed by clearing bit RBPU (OPTION_REG<7>). The ware configurable pull-ups on these four pins, allow
weak pull-up is automatically turned off when the port easy interface to a keypad and make it possible for
pin is configured as an output. The pull-ups are wake-up on key depression. Refer to the application
disabled on a Power-on Reset. note, AN552, “Implementing Wake-up on Key Stroke”
(DS00552).
FIGURE 4-4: BLOCK DIAGRAM OF RB0/INT is an external interrupt input pin and is
RB3:RB0 PINS configured using the INTEDG bit (OPTION_REG<6>).
VDD
RBPU(2)
RB0/INT is discussed in detail in Section 14.11.1 “INT
Weak Interrupt”.
P Pull-up
Data Latch
Data Bus
D Q FIGURE 4-5: BLOCK DIAGRAM OF
WR Port
I/O pin(1) RB7:RB4 PINS
CK
VDD
TRIS Latch
RBPU(2) Weak
D Q P Pull-up
TTL
WR TRIS Input Data Latch
CK Buffer Data Bus
D Q
I/O pin(1)
WR Port CK
RD TRIS
TRIS Latch
Q D D Q
Q D
Four of the PORTB pins, RB7:RB4, have an interrupt- RD Port
From other
on-change feature. Only pins configured as inputs can RB7:RB4 pins EN
cause this interrupt to occur (i.e., any RB7:RB4 pin Q3
configured as an output is excluded from the interrupt- RB7:RB6
on-change comparison). The input pins (of RB7:RB4) In Serial Programming Mode
are compared with the old value latched on the last Note 1: I/O pins have diode protection to VDD and VSS.
read of PORTB. The “mismatch” outputs of RB7:RB4 2: To enable weak pull-ups, set the appropriate TRIS
are OR’ed together to generate the RB port change bit(s) and clear the RBPU bit (OPTION_REG<7>).
interrupt with flag bit RBIF (INTCON<0>).
CKE
FIGURE 4-6: PORTC BLOCK DIAGRAM SSPSTAT<6>
(PERIPHERAL OUTPUT
Note 1: I/O pins have diode protection to VDD and VSS.
OVERRIDE) RC<2:0>, 2: Port/Peripheral Select signal selects between port data
RC<7:5> and peripheral output.
3: Peripheral OE (Output Enable) is only activated if
Peripheral Select is active.
Port/Peripheral Select(2)
Data Latch
I/O
D Q pin(1)
WR TRIS CK Q N
TRIS Latch
VSS
RD TRIS
Schmitt
Trigger
Peripheral
OE(3) Q D
EN
RD Port
Peripheral Input
RD
TRIS
Q D
ENEN
RD Port