This method is also called as Direct Port Register Addressing Technique. In this technique we use the programming methodology of AVR microcontroller programming. So to understand this method, we shall see the basics of AVR programming first. Remember that C & C++ commands are used in AVR. The pinout of ATMega328p is given below.

Unlike Arduino, in AVR programming technique, there are I/O PORTs instead of pins. The Arduino UNO uses ATMega328p microcontroller. It has 3 I/O PORTs i.e. INPUT-OUTPUT Ports: PORTB, PORTC & PORTD

  1. PORTB (8-pins): PB7 to PB0. First pin is PB7 and last pin is PB0 i.e. PB7 is at MSB and PB0 at LSB.
  2. PORTC (6-pins): PC5 to PC0. First pin is PC5 and last pin is PC0 i.e. PC5 is at MSB and PC0 at LSB.
  3. PORTD (8-pins): PD7 to PD0. First pin is PD7 and last pin is PD0 i.e. PD7 is at MSB and PD0 at LSB.

Registers in ATMega 328p

Register NameTypeRemark
DDRRead/Write1=output, 0=input
PORTRead/Write
PINRead/Write

Direct I/O PORT Register Addressing (DPRA) Technique

The Arduino can be coded using Direct PORT Register Addressing. For that we have to understand the architecture of Arduino in terms of PORTs, as shown below:

The Code

PORTwise relation with pins of Arduino
void setup() 
{
  DDRD=0b11111111; // all pins of PORTD defined as output pins
}
void loop() 
{
  PORTD=0b00000000; // LOW signal is sent on all pins of PORTD
  delay(1000);
  PORTD=0b11111111; // HIGH signal is sent on all pins of PORTD
  delay(1000);
}


Leave a Reply