2.4.1.1 GPIO Basic Functionality

The megaAVR and AVR Dx families are not pin-to-pin compatible. Thus, the GPIO basic functionality is similar and is configurable using three registers for both families:

megaAVR®AVR® DxDescription
DDRxPORTx.DIRData direction - controls the data direction (output driver)
PORTxPORTx.OUTData out - controls the output driver level for each PORTx pin
PINxPORTx.INData in - shows the state of the PORTx pin

The following code snippets show how to configure the PORTA pin 7 as output-driven high for each family.

megaAVR® - Port A, Pin 7 Configured as Output and Driven High

{
DDRA = 0x80;
PORTA = 0x80;
}

AVR® Dx - Port A, Pin 7 Configured as Output and Driven High

{
PORTA.DIR = 0x80;
PORTA.OUT = 0x80;
}