98
ATmega161(L)
1228B–09/01
Port D
Port D is an 8-bit bi-directional I/O port with internal pull-up resistors.
Three I/O address locations are allocated for the Port D, one each for the Data Register
– PORTD, $12($32), Data Direction Register – DDRD, $11($31) and the Port D Input
Pins – PIND, $10($30). The Port D Input Pins address is read-only, while the Data Reg-
ister and the Data Direction Register are read/write.
The Port D output buffers can sink 20 mA. As inputs, Port D pins that are externally
pulled low will source current if the pull-up resistors are activated.
Some Port D pins have alternate functions as shown in Table 33.
When the PD5 pin is used for the alternate function (OC1A), the DDRD and PORTD
registers have to be set according to the alternate function description.
Port D Data Register – PORTD
Port D Data Direction Register
– DDRD
Port D Input Pins Address –
PIND
The Port D Input Pins address (PIND) is not a register; this address enables access to
the physical value on each Port D pin. When reading PORTD, the Port D Data Latch is
read and when reading PIND, the logical values present on the pins are read.
Port D as General Digital I/O
PDn, general I/O pin: The DDDn bit in the DDRD register selects the direction of this pin.
If DDDn is set (one), PDn is configured as an output pin. If DDDn is cleared (zero), PDn
is configured as an input pin. If PORTDn is set (one) when configured as an input pin,
the MOS pull-up resistor is activated. To switch the pull-up resistor off, the PORTDn has
Table 33.
Port D Pin Alternate Functions
Port Pin
Alternate Function
PD0
RXD0 (UART0 Input Line)
PD1
TXD0 (UART0 Output Line)
PD2
INT0 (External Interrupt0 Input)
PD3
INT1 (External Interrupt1 Input)
PD3
TOSC1 (RTC Oscillator Timer/Counter2)
PD5
TOSC2 (RTC Oscillator Timer/Counter2)/OC1A (Timer/Counter1 Output
CompareA Match Output)
PD6
WR (Write Strobe to External Memory)
PD7
RD (Read Strobe to External Memory)
Bit
7
6
5
4
3
2
1
0
$12 ($32)
PORTD7
PORTD6
PORTD5
PORTD4
PORTD3
PORTD2
PORTD1
PORTD0
PORTD
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0
0
0
0
0
0
0
0
Bit
7
6
5
4
3
2
1
0
$11 ($31)
DDD7
DDD6
DDD5
DDD4
DDD3
DDD2
DDD1
DDD0
DDRD
Read/Write
R/W
R/W
R/W
R/W
R/W
R/W
R/W
R/W
Initial Value
0
0
0
0
0
0
0
0
Bit
7
6
5
4
3
2
1
0
$10 ($30)
PIND7
PIND6
PIND5
PIND4
PIND3
PIND2
PIND1
PIND0
PIND
Read/Write
R
R
R
R
R
R
R
R
Initial Value
N/A
N/A
N/A
N/A
N/A
N/A
N/A
N/A