2.2 Register Description
Each port pin consists of three register bits; DDRxn, PORTxn, and PINxn (x is port number, n is bit number). DDRxn is port pin input/output direction register, PORTxn is port pin data register, and PINxn is port pin input register.
The DDRxn bit in the DDRx register selects the direction of this pin. If DDxn is written to '1', Pxn is configured as an output pin. If DDxn is written to '0', Pxn is configured as an input pin.
When the pin is configured as an output pin, if PORTxn is written to '1', the port pin is driven high; if PORTxn is written '0', the port pin is driven low.
The table below summarizes the control signals for the pin value.
DDRxn | PORTxn | PUD (pull-up disable, in MCUCR) | I/O | Pull-up | Comment |
---|---|---|---|---|---|
0 | 0 | X | Input | No | Tri-state (Hi-Z) |
0 | 1 | 0 | Input | YES | Pxn will source current if ext. pulled low |
0 | 1 | 1 | Input | No | Tri-state (Hi-Z) |
1 | 0 | X | Output | No | Output Low (Sink) |
1 | 1 | X | Output | No | Output High (Source) |