Section 8.3 Pin-Change Interrupts on the ATmega328P
Pin-change interrupts are available on all I/O pins on the ATmega328P. The pin-change interrupt for each I/O pin can be individually enabled in the I/O portβs pin change mask register (
PCMSKn). As there are three I/O ports on the ATmega328P, there are three mask registers. Pin change interrupts must also be enabled on the port level using the pin change interrupt control register (PCICR).
When enabled, a pin change interrupt flag will be set when a toggle condition is present on any enabled I/O pin.
The benefit of pin change interrupts is that they are available on all of the I/O pins on the microcontroller. However, because each port has its own ISR (instead of each pin), if more than one pin interrupt is enabled on a port, conditional logic may be required to determine which of the pins triggered the interrupt. Also, because pin change interrupts are invoked on a pin toggle, if a particular logic level is desired, conditional logic will be required to determine if that logic level has been obtained.
