English
Language : 

PIC18F258 Datasheet, PDF (102/384 Pages) Microchip Technology – High Performance, 28/40-Pin Enhanced FLASH Microcontrollers with CAN
PIC18FXX8
9.4 PORTD, TRISD and LATD
Registers
Note: This port is only available on the
PIC18F448 and PIC18F458.
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 PORTD
CLRF LATD
MOVLW
MOVWF
MOVLW
07h
CMCON
0CFh
MOVWF TRISD
INITIALIZING PORTD
; Initialize PORTD by
; clearing output
; data latches
; Alternate method
; to clear output
; data latches
; comparator off
; Value used to
; initialize data
; direction
; Set RD3:RD0 as inputs
; RD5:RD4 as outputs
; RD7:RD6 as inputs
FIGURE 9-9:
PORTD BLOCK DIAGRAM IN I/O PORT MODE
PORT/PSP Select
PSP Data Out
VDD
RD LATD
P
Data Bus
WR LATD
or
PORTD
WR TRISD
RD TRISD
PSP Read
DQ
CK Q
Data Latch
DQ
CK Q
TRIS Latch
N
Vss
QD
EN
Schmitt
Trigger
RD0 pin(1)
RD PORTD
PSP Write
C1IN+
Note 1: I/O pins have diode protection to VDD and VSS.
DS41159B-page 100
Preliminary
 2002 Microchip Technology Inc.