6.3 PORTB
6.3.1 PORTB Data and Direction
PORTB is an 8Bit wide bi-directional port. The corresponding data direction register is TRISB. Set a bit
in TRISB to 1 (=1) to make the corresponding PORTB pin as the input pin. Clearing a bit in TRISB (=0) will
make the corresponding PORTB pin as the output pin.
Reading the PORTB register reads the pin status and writing to the register will write the port latch. All
write operations are read-modify-write operations. Therefore, writing a port means to read the pin level of the
port first, modify the read value, and then write the modified value into the port data latch. Even when the
PORTB pin is used as an analog input, the TRISB register still controls the direction of the PORTB pin. When
using the PORTB pin as an analog input, the user must ensure that the bits in the TRISB register remain set
as 1. I/O pin is always read 0 when configured as analog input.
Related registers with PORTB port include PORTB、TRISB、WPUB、WPDB、IOCB、ANSEL1 and etc.
PORTB data register PORTB (06H)