English
Language : 

PIC18F2331_07 Datasheet, PDF (128/400 Pages) Microchip Technology – 28/40/44-Pin Enhanced Flash Microcontrollers with nanoWatt Technology, High Performance PWM and A/D
PIC18F2331/2431/4331/4431
10.4 PORTD, TRISD and LATD
Registers
Note: PORTD is only available on PIC18F4331/
4431 devices.
PORTD is an 8-bit wide, bidirectional port. The
corresponding Data Direction register 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).
The Data Latch register (LATD) is also memory
mapped. Read-modify-write operations on the LATD
register read and write the latched output value for
PORTD.
All pins on PORTD are implemented with Schmitt
Trigger input buffers. Each pin is individually
configurable as an input or output.
Note: On a Power-on Reset, these pins are
configured as digital inputs.
PORTD includes PWM<7:6> complementary fourth
channel PWM outputs. PWM4 is the complementary
output of PWM5 (the third channel), which is multi-
plexed with the RB5 pin. This output can be used as the
alternate output using the PWM4MX Configuration bit
in CONFIG3H when the Low-Voltage Programming pin
(PGM) is used on RB5.
RD1, RD2 and RD3 can be used as the alternate out-
put for SDO, SDI/SDA and SCK/SCL using the SSPMX
Configuration bit in CONFIG3H.
RD4 an be used as the alternate output for FLTA using
the FLTAMX Configuration bit in CONFIG3H.
EXAMPLE 10-4: INITIALIZING PORTD
CLRF
CLRF
MOVLW
MOVWF
PORTD
LATD
0xCF
TRISD
; Initialize PORTD by
; clearing output
; data latches
; Alternate method
; to clear output
; data latches
; Value used to
; initialize data
; direction
; Set RD<3:0> as inputs
; RD<5:4> as outputs
; RD<7:6> as inputs
FIGURE 10-21: BLOCK DIAGRAM OF RD7:RD6
PORT/PWM Select
PWM6, 7 Data Out
0
1
RD LATD
Data Bus
WR LATD
or PORTD
D
Q
CK Q
Data Latch
D
Q
WR TRISD
CK Q
TRIS Latch
VDD
P
RD<7:6> Pin
N
VSS
RD TRISD
RD PORTD
Q
D
EN
Schmitt
Trigger
DS39616C-page 126
Preliminary
© 2007 Microchip Technology Inc.