![](http://datasheet.mmic.net.cn/330000/MB90F562_datasheet_16437954/MB90F562_216.png)
192
CHAPTER 8 I/O PORTS
MB90560 series
8.5
8.5.2 Operation of Port 2
Port 2
This section describes the operation of port 2.
I
Operation of Port 2
G
Port operation in output mode
Setting a bit of the DDR2 register to “1” places the corresponding port pin in output mode.
Data written to the PDR2 register in output mode is stored in the output latch of the PDR and
output to the port pins as is.
The PDR2 register can be accessed in read mode to read the value at the port pins (the
same value as in the output latch of the PDR).
<Check>
If a read-modify-write instruction (such as an instruction that sets bits) is used with the port
data register, the target bits of the register are set to the specified value. The bits that have
been specified for output using the DDR register are not affected, but for the bits that have
been specified for input, a value input from the pins is written to the output latch and output
as it is. Before switching the mode for the bits from input to output, therefore, write output
data to the PDR register, then specify output mode in the DDR register.
G
Port operation in input mode
Writing a bit of the DDR2 register to “0” places the corresponding port pin in input mode.
In input mode, the output buffer is turned off, and the pins are placed in a high impedance
state.
Data written to the PDR2 register in input mode is store in the output latch of the PDR but not
output to the port pins.
The PDR2 register can be accessed in read mode to read the level value (0 or 1) at the port
pins.
G
Port operation for peripheral function output
The peripheral function output enable bit is set to enable the port to be used for peripheral
function output. The state of the peripheral function enable bit takes precedence when specifying
a switch between input and output. Even if a DDR2 register bit is “0”, the corresponding port pin
is used for peripheral function output if the peripheral function has been enabled for output.
Because the value at the pins can be read even if peripheral function output is enabled, the
peripheral function output value can be read.
G
Port operation for peripheral function input
When the port is also used for peripheral function input, the value at the pins is always supplied
as peripheral function inputs. To use an external signal for the peripheral function, reset the
DDR2 register to “0” to place the port in input mode.