Exp2

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Experiment No 2

Simple Input/ Output

AIM
Write an AVR C program to read the status of DIP switches connected to port A and display it using LEDs
connected to port B.

OBJECIVES
To implement simple input/ output operations in AVR C.

COURSE OUTCOME
CO1 Develop C programs for time delays and I/O operations.

MODULE OUTCOME
M1.02 Develop simple I/O port programs

THEORY
ATMEGA ports are 8 bit wide. Each port has three 8-bit registers associated. Each bit in these registers
configures pins of associated port. Bit 0 of these registers is associated with Pin 0 of the port, Bit1 of these
registers is associated with Pin1 and so on. These three registers are
– DDRx register
– PORTx register
– PINx register
x may be replaced by A,B,C or D based on the PORT you are using.

DDRx Register
DDRx (Data Direction Register) configures data direction of the port pins. Which, writing 0 to a bit in
DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx makes the corresponding
port pin as output.

PORTx Register
PORT register is used as output register. Writing a value to the PORT register outputs through the
corresponding output pins of the microcontroller.

PINx Register
PIN register is used as input register. The data inputted to the input pins of the microcontroller stores in the
corresponding PIN register of the PORT.

PROGRAM
#include <avr/io.h>
void main()
{
unsigned char a;

DDRA = 0;
DDRB = 0xff;

while (1)
{
a = PINA;
PORTB = a;
}
}

RESULT
Studied implementation of simple I/O operations in AVR C.

You might also like