You are on page 1of 5

Handling AVR Microcontroller ports

ATmega16A pin out diagram:




























The ATmega16-A has 40 pins ,only 32 pins serve as I/O ports and the other 8 pins is
:VCC,AVCC,2xGND,AREF,RESET,XTAL1 and XTAL2.

Pin Descriptions:

1-VCC: Digital supply voltage. 2-GND: Ground.


3-AVCC: is the supply voltage pin for Port A and the A/D Converter. It should be externally connected to
VCC, even if the ADC is not used. If the ADC is used, it should be connected to VCC through a
low-pass filter.

4-AREF: is the analog reference pin for the A/D Converter.

5-XTAL1: Input to the inverting Oscillator amplifier and input to the internal clock operating circuit.

6-XTAL2: Output from the inverting Oscillator amplifier.

7-RESET: A low level on this pin for longer than the minimum pulse length will generate a
reset, even if the clock is not running.
8-Port A (PA7:PA0):

Port A serves as the analog inputs to the A/D Converter.

Port A also serves as an 8-bit bi-directional I/O port, if the A/D Converter is not used. Port pins can
provide internal pull-up resistors (selected for each bit).


9-Port B (PB7:PB0):

Port B is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).

Port B also serves the functions of various special features of the ATmega16A as listed on table below:



















10-Port C (PC7:PC0):

Port C is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).

Port C also serves the functions of the JTAG interface and other special features of the
ATmega16A as listed on table below:













11-Port D (DDC7:DDC0):

Port D is an 8-bit bi-directional I/O port with internal pull-up resistors (selected for each bit).

Port D also serves the functions of various special features of the ATmega16A as listed on table below:














































PORT SYSTEM:

The Atmel ATmega16 is equipped with four 8-bit general-purpose, digital I/O ports designated
PORTA, PORTB, PORTC, and PORTD.

For basic digital I/O port feature each port has three registers associated with it:

1-Data Register (PORTx): used to write output data to the port.

2-Data Direction Register (DDCRx): used to set a specific port pin to either output (1) or
Input (0).

3-Input Pin Address (PINx): used to read input data from the port.





































Note: AVR Studio6.1 is the compiler used in these Tutorials.
These are some examples for how to handle I/O Ports:

We can use Binary or Hexadecimal number system to set the Bits in different registers.


1- DDRC Port C Data Direction Register Data direction Input or Output:

Binary >>> DDRC = 0 b1100 1110;
Hexadecimal >>> DDRC = 0xCE;

Also we can declare it using pins definition in avr/io.h header file as showed below:

DDCx :where x is the pin number. * For other ports like A,B or D we replace C with port letter.

DDRC = ((1<<DDC7)| (1<<DDC6)| (0<<DDC5)| (0<<DDC4)| (1<<DDC3)| (1<<DDC2)| (1<<DDC1)| (0<<DDC0));



2- PORTD Port D Data Register Data value High1 or Low0:

Binary >>> PORTD = 0 b1100 1110;
Hexadecimal >>> PORTD = 0xCE;

Also we can declare it using pins definition in avr/io.h header file as showed below:

PDx :where x is the pin number. * For other ports like A,B or C we replace D with port letter.

PORTD = ((1<<PD7)| (1<<PD6)| (0<<PD5)| (0<<PD4)| (1<<PD3)| (1<<PD2)| (1<<PD1)| (0<<PD0));



3- PIND Port D Input Pins Address:

Binary >>> PIND = 0 b1100 1110;
Hexadecimal >>> PIND = 0xCE;

Also we can declare it using pins definition in avr/io.h header file as showed below:

PDx :where x is the pin number. * For other ports like A,B or C we replace D with port letter.

PIND = ((1<<PD7)| (1<<PD6)| (0<<PD5)| (0<<PD4)| (1<<PD3)| (1<<PD2)| (1<<PD1)| (0<<PD0));

While using PIN register we have to set the Data direction to input to make sure that the pin will sense the
input coming from the pin.

EX:
DDRC = 0 b0000 0000; I have set the data direction to input in all PORTC pins
PINC = 0 b1101 1010; then the Bits on PINC show the data input

***We mainly use PINx register in if statement to check the INPUT

You might also like