Datasheet
2011 Microchip Technology Inc. DS39932D-page 135
PIC18F46J11 FAMILY
10.2 PORTA, TRISA and LATA Registers
PORTA is a 7-bit wide, bidirectional port. It may
function as a 5-bit port, depending on the oscillator
mode selected. Setting a TRISA bit (= 1) will make the
corresponding PORTA pin an input (i.e., put the
corresponding output driver in a high-impedance
mode). Clearing a TRISA bit (= 0) will make the
corresponding PORTA pin an output (i.e., put the
contents of the output latch on the selected pin).
Reading the PORTA register reads the status of the
pins, whereas writing to it, will write to the port latch.
The Data Latch (LATA) register is also memory mapped.
Read-modify-write operations on the LATA register read
and write the latched output value for PORTA.
The other PORTA pins are multiplexed with analog
inputs, the analog V
REF+ and VREF- inputs and the com-
parator voltage reference output. The operation of pins,
RA<3:0> and RA5, as A/D converter inputs is selected
by clearing or setting the control bits in the ANCON0
register (A/D Port Configuration Register 0).
Pins, RA0 and RA3, may also be used as comparator
inputs by setting the appropriate bits in the CMCON reg-
ister. To use RA<3:0> as digital inputs, it is also
necessary to turn off the comparators.
All PORTA pins have TTL input levels and full CMOS
output drivers.
The TRISA register controls the direction of the PORTA
pins, even when they are being used as analog inputs.
The user must ensure the bits in the TRISA register are
maintained set when using them as analog inputs.
EXAMPLE 10-2: INITIALIZING PORTA
Note: On a Power-on Reset (POR), RA5 and
RA<3:0> are configured as analog inputs
and read as ‘0’.
CLRF LATA ; Initialize LATA
; to clear output
; data latches
MOVLB 0x0F ; ANCONx register not in
; Access Bank
MOVLW 0x0F ; Configure A/D
MOVWF ANCON0 ; for digital inputs
MOVLW 0xCF ; Value used to
; initialize data
; direction
MOVWF TRISA ; Set RA<3:0> as inputs
; RA<5:4> as outputs