PIC16F8X
5.2
PORTB and TRISB Registers
PORTB is an 8-bit wide bi-directional port. The
corresponding data direction register is TRISB. A '1' on
any bit in the TRISB register puts the corresponding
output driver in a hi-impedance mode. A '0' on any bit
in the TRISB register puts the contents of the output
latch on the selected pin(s).
Each of the PORTB pins have a weak internal pull-up.
A single control bit can turn on all the pull-ups. This is
done by clearing the RBPU (OPTION_REG<7>) bit.
The weak pull-up is automatically turned off when the
port pin is con铿乬ured as an output. The pull-ups are
disabled on a Power-on Reset.
Four of PORTB鈥檚 pins, RB7:RB4, have an interrupt on
change feature. Only pins con铿乬ured as inputs can
cause this interrupt to occur (i.e., any RB7:RB4 pin
con铿乬ured as an output is excluded from the interrupt
on change comparison). The pins value in input mode
are compared with the old value latched on the last
read of PORTB. The 鈥渕ismatch鈥?outputs of the pins are
OR鈥檈d together to generate the RB port
change interrupt.
This interrupt can wake the device from SLEEP. The
user, in the interrupt service routine, can clear the
interrupt in the following manner:
a)
b)
Read (or write) PORTB. This will end the mis-
match condition.
Clear 铿俛g bit RBIF.
A mismatch condition will continue to set the RBIF bit.
Reading PORTB will end the mismatch condition, and
allow the RBIF bit to be cleared.
This interrupt on mismatch feature, together with
software con铿乬urable pull-ups on these four pins allow
easy interface to a key pad and make it possible for
wake-up on key-depression (see AN552 in the
Embedded Control Handbook).
Note 1:
For a change on the I/O pin to be
recognized, the pulse width must be at
least T
CY
(4/f
OSC
) wide.
The interrupt on change feature is recommended for
wake-up on key depression operation and operations
where PORTB is only used for the interrupt on change
feature. Polling of PORTB is not recommended while
using the interrupt on change feature.
FIGURE 5-3:
BLOCK DIAGRAM OF PINS
RB7:RB4
V
DD
FIGURE 5-4:
RBPU
(1)
BLOCK DIAGRAM OF PINS
RB3:RB0
V
DD
weak
P pull-up
Data Latch
D
Q
CK
TRIS Latch
D
Q
I/O
pin
(2)
RBPU
(1)
Data Latch
D
CK
TRIS Latch
D
WR TRIS
CK
Q
Q
weak
P pull-up
Data bus
WR Port
Data bus
WR Port
I/O
pin
(2)
WR TRIS
TTL
Input
Buffer
CK
TTL
Input
Buffer
RD TRIS
RD TRIS
Latch
Q
RD Port
Set RBIF
From other
RB7:RB4 pins
D
EN
RB0/INT
Schmitt Trigger
Buffer
Note 1: TRISB = '1' enables weak pull-up
(if RBPU = '0' in the OPTION_REG register).
2: I/O pins have diode protection to V
DD
and V
SS
.
RD Port
Note 1: TRISB = '1' enables weak pull-up
(if RBPU = '0' in the OPTION_REG register).
2: I/O pins have diode protection to V
DD
and V
SS
.
RD Port
RD Port
Q
D
EN
Q
D
EN
漏
1998 Microchip Technology Inc.
DS30430C-page 23