Datasheet
69
7728G–AVR–06/10
ATtiny87/ATtiny167
9.2.2 Toggling the Pin
Writing a logic one to PINxn toggles the value of PORTxn, independent on the value of
DDRxn. Note that the SBI assembler instruction can be used to toggle one single bit in a port.
9.2.3 Break-Before-Make Switching
In the Break-Before-Make mode when switching the DDRxn bit from input to output an imme-
diate tri-state period lasting one system clock cycle is introduced as indicated in Figure 9-3.
For example, if the system clock is 4 MHz and the DDRxn is written to make an output, the
immediate tri-state period of 250 ns is introduced, before the value of PORTxn is seen on the
port pin. To avoid glitches it is recommended that the maximum DDRxn toggle frequency is
two system clock cycles. The Break-Before-Make is a port-wise mode and it is activated by the
port-wise BBMx enable bits. For further information about the BBMx bits, see “Port Control
Register – PORTCR” on page 75. When switching the DDRxn bit from output to input there is
no immediate tri-state period introduced.
Figure 9-3. Break Before Make, switching between input and output
9.2.4 Switching Between Input and Output
When switching between tri-state ({DDxn, PORTxn} = 0, 0) and output high
({DDxn, PORTxn} = 1, 1), an intermediate state with either pull-up enabled
{DDxn, PORTxn} = 0, 1) or output low ({DDxn, PORTxn} = 1, 0) must occur. Normally, the
pull-up enabled state is fully acceptable, as a high-impedant environment will not notice the
difference between a strong high driver and a pull-up. If this is not the case, the PUD bit in the
MCUCR Register or the PUDx bit in PORTCR Register can be set to disable all pull-ups in the
port.
Switching between input with pull-up and output low generates the same problem. The user
must use either the tri-state ({DDxn, PORTxn} = 0, 0) or the output high state
({DDxn, PORTxn} = 1, 1) as an intermediate step.
tri-state
tri-state
tri-state
0x02
0x020x01 0x01
0x01
0x55
nop
immediate tri-state cycle
out DDRx, r16
YSTEM CLOCK
R 16
R 17
NSTRUCTIONS
PORTx
DDRx
Px0
Px1
out DDRx, r17
immediate tri-state cycle