AVR was developed by Atmel in 1996 as a single chip microcontroller. AVR is a family of 8-bit microcontrollers that are based on modified Harvard architecture of type RISC(Reduced Instruction Set Computer) which works on executing simplified instructions in a regular clock cycle following a pipelining approach.
Classification of AVR series:
tinyAVR – the ATtiny series
megaAVR – the ATmega series
XMEGA – the ATxmega series
It is essential to first understand the Pin Out diagram of ATMega 16.
I/O and Packages
Power Consumption @ 1 MHz, 3V, and 25°C for ATmega16L
In order to connect AVR microcontroller with a PC for programming, an AVR programmer is required i.e. USBASP.
The programmer consists of a USB cable used to connect with PC/laptop and an SPI cable used to connect to the MUC.
All ports of AVR are 8-bit long and every port consists of three registers. Each constituting bit in these registers configure pins of the particular port.
In each register, Bit0 is associated with Pin0 of the port, Bit1 is associated with Pin1 of the port, it goes like wise for all other bits.
The three registers that comprise one port are as follows:
Here, x can be replaced by A, B, C, and D as per the Port being used.
DDRX are Data Direction Registers that perform the function of configuring the Pins as either input or output.
‘1’ implies that the corresponding pin is configured as output.
‘0’ implies that the corresponding pin is configured as input.
Let’s take an example:
Here, the 1st,2nd,and 5th pin of PORT X have been configured as output, while the remaining pins have been configured as input i.e. these are ready to accept data.
Ports are directly connected to the pins. If the corresponding DDR pin is configured as output, then these registers are used to provide value to the connected device (such as LEDs, Motors etc.).
Eg: If you want to pass ‘1’ at 5th pin of X PORT of the microcontroller which is connected to a device(LEDs/Motors), it should be set as:
But, before passing this value the 5th pin of X port should be configured as an output using the DDR of the PORT.
If the DDR pin is configured as an input, then these registers are used for deriving the value from the connected device (such as sensors).
Eg: If you want to read ‘1’ at 5th pin of X PORT of the microcontroller which is connected to a device (sensors), it should be set as:
But, before reading the value from the 5th pin of X port, the corresponding pin should be configured as an input using the DDR of the PORT.