AVR microcontrollers are the advanced microcontrollers. From 1996 onwards these are come into existence. In AVR family there are so many controllers are available. Mainly the AVR family is sub grouped as ATmega, ATtiny, Xmega, UC3, SAM3 and SAM4. In these form 8 to 32 bit controllers are available. All the controllers having some common and some different features, those are coming to common features all are having I/O ports, timer/counters, interrupts and etc, coming to special features those are A/D converters, PWM, D/A converter, on chip I2C, serial communication interfacings, on chip EEPROM and etc. we can use all these features according to our requirement by programming.
First we have to discuss about I/O ports. Generally AVR microcontrollers having four I/O ports named as PORTA, PORTB, PORTC, PORTD. Take example as ATMEGA8 or ATMEGA 16 or ATMEGA32 microcontrollers, these are any having four I/O ports and each port having 8 I/O lines and totally each controller having 32 I/O lines. These 32 I/O lines are bi-directional means we can use these I/O lines either input or output. In addition to each this pin has some of other functions like ADC, timers, interrupts, serial communication pins and other pins. To perform any operation with general purpose I/O (GPIO) pins there is a need to configure three registers. Those registers named as DDRx, PORTx, PINx (here ‘x’ indicates the name of the register A or B or C or D).
Each registers of these three registers are 8-bit registers means generally each port has 8 pins as like each register has 8-bits and each pin refers on bit of register. If we want to configure any pin of the port we can configure the corresponding bits of all three registers. In this article I am taking example as ATMEGA32 microcontroller. Now conceder pins 22-29 of the microcontroller, if we want to configure these 8-pins, there is a need of configure corresponding three registers of 8-bits. Here explaining clearly, in ATMEGA32 pin 22-29 refers PORTC. So if we want to configure PORTC, we need to configure DDRC, PORTC and PINC registers.
These 8-bits are divided into two 4-bit groups and named as lower nibbles upper nibbles. 0-3 bits are called as lower nibbles and 4-7 bits are called as upper nibbles.
Configuring the PORT:
We have discussed above that if want to configure one port; there is a need to configure corresponding three registers of the port. So now we are configuring the PORTc, so we need to configure DDRC, PORTC and PINC registers. Now we can discuss in detail about these three registers here.
DDRx register:
The name of the register is Data Direction Register. The name only indicates complete use of the register that is data direction. There are only two directions. Those are controller to module and module to controller. If data direction is from module to controller that is input, if data is passing from controller to module that is output. So the two directions are input direction and output direction.
This register is used to assign the pin of the port as either input direction or output direction. In this register the port and pin indicated as “DDRxn”, here ‘x’ indicates the port name and ‘n’ indicates the pin number. For example pin 26 refers to 4th pin of PORTC is defined as DDRC4. Generally these GPIO pins are digital I/O pins that mean these are having only two logics as logic0 and logic1. Same like these DDR also. If DDRxn is written as logic one, the pin is configured as output pin. If DDRxn is written as logic zero, the pin is configured as input pin.
I am an experienced technical writer holding a Master's degree in computer science from BZU Multan, Pakistan University. With a background spanning various industries, particularly in home automation and engineering, I have honed my skills in crafting clear and concise content. Proficient in leveraging infographics and diagrams, I strive to simplify complex concepts for readers. My strength lies in thorough research and presenting information in a structured and logical format.
This website uses cookies to improve your experience. We'll assume you're ok with this, but you can opt-out if you wish.ACCEPTPrivacy Policy
Manage consent
Privacy Overview
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.