Input Output Programming in AVR Microcontroller
Input Output Programming in AVR Microcontroller
INPUT/OUTPUT
PORTS
A
B
C
D
=
=
=
=
8 Pins
8 Pins
8 Pins
8 Pins
Port
X
DDRX
PORTX
PINX
USES OF REGISTER
DDRX For setting the direction i.e. Input
or output.
PORTX For setting output value of port.
PINX For reading data available in port.
NOTE:- X is the name of port and it can be
A,
B, C or D .
DEFINING PORT
(DATA DIRECT REGISTER)
DDRX= 0xFF; (O/P-Port)
DDRX= 0x00; (I/P-Port)
or
DDRX = 0b 1 1 1 1 1 1 1 1 ; (O/PPort)
DDRX = 0b 0 0 0 0 0 0 0 0 ; (I/PPort)
NOTE:- X is the name of port and it
can
be A, B, C or D .
bit_is_set(PINX,0))
input
//Detecting
IF - LOOP
if (bit_is_set(PINX,0)))
{ code to be executed }
if (bit_is_clear(PINX,0)))
{ code to be executed }
WHILE - LOOP
while(bit_is_set(PINX,0)))
{ code to be executed }
while(bit_is_clear(PINX,0)))
{ code to be executed }
INCLUDE
#include <avr/io.h>
#include <util/delay.h>
THANKS