Microchip Technology DV164136 Data Sheet

Page of 466
PIC18F87J11 FAMILY
DS39778E-page 140
 
 2007-2012 Microchip Technology Inc.
11.2
PORTA, TRISA and 
LATA Registers
PORTA is an 8-bit wide, bidirectional port. It may func-
tion as a 6-bit or 7-bit port, depending on the oscillator
mode selected. The corresponding Data Direction and
Output Latch registers are TRISA and LATA.
The RA4 pin is multiplexed with the Timer0 module
clock input to become the RA4/T0CKI pin; it is also mul-
tiplexed as the Parallel Master Port data pin (in 80-pin
devices). The other PORTA pins are multiplexed with
the analog V
REF
+ and V
REF
- inputs. The operation of
pins, RA<5,3:0>, as A/D Converter inputs is selected
by clearing or setting the appropriate PCFGx control
bits in the ANCON0 register.
The RA4/T0CKI pin is a Schmitt Trigger input. All other
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. 
OSC2/CLKO/RA6 and OSC1/CLKI/RA7 normally
serve as the external circuit connections for the
external (primary) oscillator circuit (HS and HSPLL
Oscillator modes), or the external clock input (EC and
ECPLL Oscillator modes). In these cases, RA6 and
RA7 are not available as digital I/O, and their
corresponding TRIS and LAT bits are read as ‘0’. 
For INTIO and INTPLL Oscillator modes (FOSC2 Con-
figuration bit is ‘0’), either RA7 or both RA6 and RA7
automatically become available as digital I/O, depend-
ing on the oscillator mode selected. When RA6 is not
configured as a digital I/O, in these cases, it provides a
clock output at F
OSC
/4. A list of the possible configura-
tions for RA6 and RA7, based on oscillator mode, is
provided in 
. For these pins, the correspond-
ing PORTA, TRISA and LATA bits are only defined
when the pins are configured as I/O.
TABLE 11-3:
FUNCTION OF RA<7:6> IN 
INTIO AND INTPLL MODES
EXAMPLE 11-2:
INITIALIZING PORTA   
Note 1:
RA5 (RA5/PMD4/AN4) is multiplexed as
an analog input in all devices and Parallel
Master Port data in 80-pin devices. 
2:
RA5 and RA<3:0> are configured as
analog inputs on any Reset and are read
as ‘0’. RA4 is configured as a digital input.
Oscillator Mode
(FOSC<2:0> Configuration)
RA6
RA7
INTPLL1 (011)
CLKO
I/O
INTPLL2 (010)
I/O
I/O
INTIO1 (001)
CLKO
I/O
INTIO2 (000)
I/O
I/O
Legend:
CLKO = F
OSC
/4 clock output; 
I/O = digital port.
CLRF
PORTA
; Initialize PORTA by
; clearing output
; data latches
CLRF
LATA 
; Alternate method to
 
; clear  data latches
BSF
WDTCON,ADSHR ; Enable write/read to
; the shared SFR
MOVLW
1Fh 
; Configure A/D
MOVWF
ANCON0 
; for digital inputs
BCF
WDTCON,ADSHR ; Disable write/read
; to the shared SFR
MOVLW
H'CF' 
; Value used to
; initialize
; data direction
MOVWF
TRISA 
; Set RA<3:0> as inputs,
; RA<5:4> as outputs