English
Language : 

PIC16LF18854 Datasheet, PDF (208/668 Pages) Microchip Technology – C Compiler Optimized RISC Architecture
PIC16(L)F18856/76
12.6 PORTB Registers
12.6.1 DATA REGISTER
PORTB is an 8-bit wide, bidirectional port. The
corresponding data direction register is TRISB
(Register 12-13). Setting a TRISB bit (= 1) will make
the corresponding PORTB pin an input (i.e., disable the
output driver). Clearing a TRISB bit (= 0) will make the
corresponding PORTB pin an output (i.e., enables
output driver and puts the contents of the output latch
on the selected pin). Example 12.4.9 shows how to
initialize PORTB.
Reading the PORTB register (Register 12-12) reads
the status of the pins, whereas writing to it will write to
the PORT latch. All write operations are
read-modify-write operations. Therefore, a write to a
port implies that the port pins are read, this value is
modified and then written to the PORT data latch
(LATB).
The PORT data latch LATB (Register 12-14) holds the
output port data, and contains the latest value of a
LATB or PORTB write.
EXAMPLE 12-2: INITIALIZING PORTA
; This code example illustrates
; initializing the PORTA register. The
; other ports are initialized in the same
; manner.
BANKSEL PORTA
;
CLRF PORTA
;Init PORTA
BANKSEL LATA
;Data Latch
CLRF LATA
;
BANKSEL ANSELA
;
CLRF ANSELA
;digital I/O
BANKSEL TRISA
;
MOVLW B'00111000' ;Set RA<5:3> as inputs
MOVWF TRISA
;and set RA<2:0> as
;outputs
12.6.2 DIRECTION CONTROL
The TRISB register (Register 12-13) controls the
PORTB pin output drivers, even when they are being
used as analog inputs. The user should ensure the bits
in the TRISB register are maintained set when using
them as analog inputs. I/O pins configured as analog
inputs always read ‘0’.
12.6.3 OPEN-DRAIN CONTROL
The ODCONB register (Register 12-17) controls the
open-drain feature of the port. Open-drain operation is
independently selected for each pin. When an
ODCONB bit is set, the corresponding port output
becomes an open-drain driver capable of sinking
current only. When an ODCONB bit is cleared, the
corresponding port output pin is the standard push-pull
drive capable of sourcing and sinking current.
Note:
It is not necessary to set open-drain
control when using the pin for I2C; the I2C
module controls the pin and makes the pin
open-drain.
12.6.4 SLEW RATE CONTROL
The SLRCONB register (Register 12-18) controls the
slew rate option for each port pin. Slew rate control is
independently selectable for each port pin. When an
SLRCONB bit is set, the corresponding port pin drive is
slew rate limited. When an SLRCONB bit is cleared,
The corresponding port pin drive slews at the maximum
rate possible.
DS40001824A-page 208
Preliminary
 2016 Microchip Technology Inc.