Controlling pins is one of the first things to learn when learning microcontrollers. It seems that each microcontroller type has its own port logic’s. So before using them it is important to understand every detail of it so you could efficiently use in projects. Let’s see how ports are organized in AVR and how successfully control them.
Inside AVR port
If you try to look in to any AVR datasheet you will find port drawing which may seem a bit complex at the start. But for a simple start let’s look at simplified port pin schematic.
As you can see each port consists of three registers DDRx PORTx, and PINx (for instance DDRA, PORTA and PINA). When looking in to this simple logic we can see several variants of operation. In order to enable output to pin we need to write logic ‘1’ to DDx.n pin. This will enable buffer to let bit through from PORTx register. If PORTx.n bit is ‘1’ then it can source pin with VCC voltage and up to 20mA of source; in other hand if logic ‘0’ is written then pin can source the target circuit. Read more »