32
ATtiny22/22L
I/O Port B
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports. This means that the direc-
tion of one port pin can be changed without unintentionally changing the direction of any other pin with the SBI and CBI
instructions. The same applies for changing drive value (if configured as output) or enabling/disabling of pull-up resistors (if
configured as input).
Port B is a 5-bit bi-directional I/O port.
Three I/O memory address locations are allocated for Port B, one each for the Data Register - PORTB, $18 ($38), Data
Direction Register - DDRB, $17($37) and the Port B Input Pins - PINB, $16($36). The Port B Input Pins address is read
only, while the Data Register and the Data Direction Register are read/write.
All port pins have individually selectable pull-up resistors. The Port B output buffers can sink 20mA and thus drive LED dis-
plays directly. When pins PB0 to PB4 are used as inputs and are externally pulled low, they will source current if the
internal pull-up resistors are activated.
The Port B pins with alternate functions are shown in the following table:
When the pins are used for the alternate function the DDRB and PORTB register has to be set according to the alternate
function description.
Port B Data Register - PORTB
Port B Data Direction Register - DDRB
Port B Input Pins Address - PINB
The Port B Input Pins address - PINB - is not a register, and this address enables access to the physical value on each Port
B pin. When reading PORTB, the Port B Data Latch is read, and when reading PINB, the logical values present on the pins
are read.
Table 10. Port B Pins Alternate Functions
Port Pin
Alternate Functions
PB0
MOSI (Data input line for memory downloading)
PB1
MISO (Data output line for memory uploading)
INT0 (External Interrupt0 Input)
PB2
SCK (Serial clock input for serial programming)
TO (Timer/Counter0 counter clock input)
PB3
CLOCK (Clock input)
Bit
7
6
5
4
3
2
1
0
$18 ($38)
-
-
-
PORTB4
PORTB3
PORTB2
PORTB1
PORTB0
PORTB
Read/Write
R
R
R
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
$17 ($37)
-
-
-
DDB4
DDB3
DDB2
DDB1
DDB0
DDRB
Read/Write
R
R
R
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
$16 ($36)
-
-
-
PINB4
PINB3
PINB2
PINB1
PINB0
PINB
Read/Write
R
R
R
R
R
R
R
R
Initial value
0
0
0
Hi-Z
Hi-Z
Hi-Z
Hi-Z
Hi-Z