
PIC18FXX8
DS41159B-page 100
Preliminary
2002 Microchip Technology Inc.
9.4
PORTD, TRISD and LATD
Registers
PORTD is an 8-bit wide, bi-directional port. The corre-
sponding Data Direction register for the port is TRISD.
Setting a TRISD bit (=
‘
1
’
) will make the corresponding
PORTD pin an input (i.e., put the corresponding output
driver in a High-Impedance mode). Clearing a TRISD
bit (=
‘
0
’
) will make the corresponding PORTD pin an
output (i.e., put the contents of the output latch on the
selected pin).
Read-modify-write operations on the LATD register
reads and writes the latched output value for PORTD.
PORTD is uses Schmitt Trigger input buffers. Each pin
is individually configurable as an input or output.
PORTD can be configured as an 8-bit wide micro-
processor port (Parallel Slave Port, or PSP) by setting
the control bit PSPMODE (TRISE<4>). In this mode,
the input buffers are TTL. See Section 10.0 for
additional information on the Parallel Slave Port.
PORTD is also multiplexed with the analog comparator
module and the ECCP module.
EXAMPLE 9-4:
CLRF
INITIALIZING PORTD
; Initialize PORTD by
; clearing output
; data latches
; Alternate method
; to clear output
; data latches
; comparator off
FIGURE 9-9:
PORTD BLOCK DIAGRAM IN I/O PORT MODE
Note:
This port is only available on the
PIC18F448 and PIC18F458.
PORTD
CLRF
LATD
MOVLW
MOVWF
MOVLW
07h
CMCON
0CFh
; Value used to
; initialize data
; direction
; Set RD3:RD0 as inputs
; RD5:RD4 as outputs
; RD7:RD6 as inputs
MOVWF
TRISD
PORT/PSP Select
Data Bus
WR LATD
or
PORTD
WR TRISD
Data Latch
TRIS Latch
RD TRISD
Q
D
Q
CK
Q
D
EN
Q
D
Q
CK
P
N
V
DD
Vss
RD PORTD
RD0 pin
(1)
RD LATD
Schmitt
Trigger
Note
1:
I/O pins have diode protection to V
DD
and V
SS
.
PSP Data Out
PSP Write
PSP Read
C1IN+