Basic Input Output Registers  
All AVR ports have true Read-Modify-Write functionality when used as general digital I/O ports.

There are total of 4 PORTs in an ATmega16, each consists of 8bit I/O lines. It means ATmega16 has total of 32 I/O lines each can be individually configured either as Input or as Output at any time, without affecting the operation of other pins.

Each port of AVR MC has total three register with it. These three registers are used to configure/modify values and modes of different I/O lines.

Three registers are named as PORTx, DDRx and PINx. (x is port number A,B,C,D)

First let me explain DDRx registers. DDR is acronym for "Data Direction Register". As name suggests it defines the direction of data on any port. In AVR MCs we must specify, how we are going to use some PORT pin? either we are using it for input purpose or for output purpose. DDRx(n) bit selects the direction of any pin (n) of PORTx. IF DDRx(n) is written logic '1', PORTx(n) is now declared as an output pin. IF DDRx(n) is written logic '0', PORTx(n) is now declared as an input pin.

Now let us discuss PORTx registers. PORTx is the register which refelects the current logic value on PORTx(n) pin. For example if we write logic '1' on PORTA_3 (3rd bit of PORTA), it means that we want 3rd bit of PORTA to go into a high logic state. Similarly if we write logic '0' on PORTA_3, it means we want 3rd bit of PORTA to go to a logic '0' state.



The PINx(n) register is a read only register that reflects the current logical value on the port pin. The PINx register is primarily used when the port is programmed as input.

DDRx(n) PORTx(n) Description
0 0 Pin configured as input, Pull up disabled (Floating)
0 1 Pin configured as input, Pull Up enabled.
1 0 Pin configured as output, with low level on pin (Current Sink).
1 1 Pin configured as output, with high level on pin (Current Source).

devesh@electroons.com
Best viewed at Firefox 1024x768 resolution