English
Language : 

PIC18F87K22 Datasheet, PDF (181/548 Pages) Microchip Technology – 64/80-Pin, High-Performance, 1-Mbit Enhanced Flash Microcontrollers with 12-Bit A/D and nanoWatt XLP Technology
PIC18F87K22 FAMILY
12.8 PORTG, TRISG and
LATG Registers
PORTG is a 5-bit wide, bidirectional port. The
corresponding Data Direction and Output Latch registers
are TRISG and LATG.
PORTG is multiplexed with AUSART and CCP, ECCP,
Analog, Comparator, RTCC and Timer input functions
(Table 12-13). When operating as I/O, all PORTG pins
have Schmitt Trigger input buffers. The open-drain
functionality for the CCPx and UART can be configured
using ODCONx.
When enabling peripheral functions, care should be
taken in defining TRIS bits for each PORTG pin. Some
peripherals override the TRIS bit to make a pin an
output, while other peripherals override the TRIS bit to
make a pin an input. The user should refer to the
corresponding peripheral section for the correct TRIS bit
settings. The pin override value is not loaded into the
TRIS register. This allows read-modify-write of the TRIS
register without concern due to peripheral overrides.
EXAMPLE 12-7: INITIALIZING PORTG
CLRF PORTG
BCF
CLRF
CM1CON, CON
LATG
BANKSEL ANCON2
MOVLW 0F0h
MOVWF ANCON2
BANKSEL TRISG
MOVLW 04h
MOVWF TRISG
; Initialize PORTG by
; clearing output
; data latches
; disable
; comparator 1
; Alternate method
; to clear output
; data latches
; Select bank with ACON2 register
; make AN16 to AN19
; digital
; Select bank with TRISG register
; Value used to
; initialize data
; direction
; Set RG1:RG0 as
; outputs
; RG2 as input
; RG4:RG3 as inputs
TABLE 12-13: PORTG FUNCTIONS
Pin Name
Function
TRIS
Setting
I/O
I/O
Type
Description
RG0/ECCP3/
P3A
RG0
0
O
DIG LATG<0> data output.
1
I
ST PORTG<0> data input.
ECCP3
0
O
DIG ECCP3 compare output and ECCP3 PWM output. Takes priority over
port data.
1
I
ST ECCP3 capture input.
P3A
0
O
— ECCP3 PWM Output A.
May be configured for tri-state during Enhanced PWM shutdown
events.
RG1/TX2/CK2/
AN19/C3OUT
RG1
0
O
DIG LATG<1> data output.
1
I
ST PORTG<1> data input.
TX2
1
O
DIG Synchronous serial data output (EUSART module); takes priority over
port data.
CK2
1
O
DIG Synchronous serial data input (EUSART module); user must configure
as an input.
1
I
ST Synchronous serial clock input (EUSART module).
AN19
1
I
ANA A/D Input Channel 19.
Default input configuration on POR. Does not affect digital output.
C3OUT
x
O
DIG Comparator 3 output.
Legend: O = Output, I = Input, ANA = Analog Signal, DIG = Digital Output, ST = Schmitt Trigger Buffer Input,
x = Don’t care (TRIS bit does not affect port direction or is overridden for this option).
 2010 Microchip Technology Inc.
Preliminary
DS39960B-page 181