Skip to main content

Microcontrollers

Chapter 5 I/O Ports

Microcontrollers are only interesting insofar as they can interact with input and output devices. The gatekeeper between a microcontroller and external devices are I/O pins. The ATmega328P has three I/O ports that connect to each of the I/O pins. These ports are called Port B, Port C, and Port D.
The pins associated with each of these ports are listed in Table 5.0.1. The labeling used for the ATmega328P differs from the labeling used by Arduino Uno R3. Note that the ATmega328P has more available I/O pins than the Arduino Uno R3. The Arduino platform has external hardware connected to pins PB6, PB7, and PC5, so they are not available for general I/O usage. The Arduino labeling of pins in Port C with the letter A is due to the fact that these pins can act as an input source to the analog to digital converter (ADC), which is discussed in Chapter 6. This does not mean that the pins on Port C are “analog” pins. All I/O pins on the ATmega328P are digital I/O pins.
Table 5.0.1. I/O pin labeling on the ATmega328P and Arduino Uno R3
Port B
bit 7 6 5 4 3 2 1 0
ATmega328P PB7 PB6 PB5 PB4 PB3 PB2 PB1 PB0
Arduino Uno R3 D13 D12 D11 D10 D9 D8
Port C
bit 7 6 5 4 3 2 1 0
ATmega328P PC6 PC5 PC4 PC3 PC2 PC1 PC0
Arduino Uno R3 A5 A4 A3 A2 A1 A0
Port D
bit 7 6 5 4 3 2 1 0
ATmega328P PD7 PD6 PD5 PD4 PD3 PD2 PD1 PD0
Arduino Uno R3 D7 D6 D5 D4 D3 D2 D1 D0