138
CHAPTER 4 I/O PORTS
4.3.2
Operation of Port 2
This section describes the operations of the port 2.
s Operation of Port 2
r Operation as an output port
Setting the corresponding DDR2 register bit to "1" sets a pin as an output port.
When a pin is as an output port, the output transistor is enabled. When the output latch value
is "0", the output transistor turns "ON" and an "L" level is output from the pin. When the
output latch value is "1" the transistor turns "OFF" and the pin goes to the high-impedance
state. If a pull-up is set to the output pin, the pin goes to the pull-up state when the output
latch value is "1".
Writing data to the PDR2 register stores the data in the output latch and outputs the data to
the pin.
Reading the PDR2 register returns the pin value.
r Operation as an input port
Setting the corresponding DDR2 register bit to "0" sets a pin as an input port.
When a pin is set as an input port, the output transistor is "OFF" and the pin goes to the
high-impedance state.
Writing data to the PDP2 register stores the data in the output latch but does not output the
data to the pin.
Reading the PDR2 register returns the pin value.
r Operation as a peripheral output
If a peripheral output enable bit is set to "enable", the corresponding pin becomes a
peripheral output.
As the pin value can be read even if the peripheral output is enabled, the peripheral output
value can be read via the PDR2 register.
r Operation as a peripheral input
A port pin is set as a peripheral input by setting the corresponding DDR2 register bit to "0".
Reading the PDR2 register returns the pin value, regardless of whether or not the peripheral
is using the input pin.
r Operation at reset
Resetting the CPU initializes the DDR2 register value to "0". This sets output transistors
"OFF" (pins become input ports) and sets the pins to the high-impedance state.
The PDR2 register is not initialized by a reset. Therefore, to use as output ports, the output
data must be set in the PDR2 register before setting the corresponding DDR2 register bit to
output mode.
Pin state of P27 is undetermined until the internal clock starts operation.