AVR C Programming - Hardware Registers



UpdatedUpdatedOctober 06 - 2017October 06 - 2017

Summary

A microcontroller is all about reading inputs, processing it and generating outputs. So learning I/O registers and their correct settings is the most essential part of our course.

AVR uC

AVR is an 8-bit microcontroller. This means that all the Ports are 8-bit wide.
For example, on our myAVR board we have an ATmega8 microcontroller. The pin configuration of this microcontroller is given below (PDIP package):

atmega8_PDIP.jpg


As we can see, ATmega8 has 3 Ports:

  • Port-B (PB0, PB1, PB2, PB3, PB4, PB5, PB6, PB7 8 pins)
  • Port-C (PC0, PC1, PC2, PC3, PC4, PC5, PC6 7 pins)
  • Port-D (PD0, PD1, PD2, PD3, PD4, PD5, PD6, PD7 8 pins)

But in our myAVR MK2 board the following pins are available to use as I/O pins:

  • Port-B (PB0, PB1, PB2, PB3, PB4, PB5 6 pins)
  • Port-C (PC0, PC1, PC2, PC3, PC4, PC5 6 pins)
  • Port-D (PD2, PD3, PD4, PD5, PD6, PD7 6 pins)

Registers

In an AVR microcontroller every Port has 3 registers associated with it. These registers are:

  • DDRx
  • PORTx
  • PINx
Note: x is replaced by A, B, C or D as per your avr microcontroller.