Programming The Digital I
Programming The Digital I
The AVR C code below shows how to configure the pins on a port
DDRA = 0xFF;
DDRB = 0x00;
DDRC = 0xF0;
The AVR C code below shows how to write to or read from the pins of a port once they are
configured. Assume here the configurations from the C code above.
PORTA = 0xFF;
PORTA = PINB;
Solution
The program below, written in AVR Studio 5 and AVR Studio 6, accomplish the task that
was asked above. There are several things to note here.
1. The header file avr/io.h must be included in order for us to use the name of the
ports.
2. The ports must be configured before they are used. The first two(2) lines in the
main() function of the program are for configuration.
3. Once the ports are configured you can then write to or read from them, were
applicable.
4. The use of the while(1) loop allows for the continuous read and write operation.
/*
*
*
*
*
*
*/
#include<avr/io.h>
int main()
{
DDRB = 0x00;
DDRC = 0xFF;
while(1)
{
PORTC = PINB;
}
return 0;
For another Digital I/O C programming example check out the Interfacing LEDs with the AVR
Microcontrollerstutorial.
AVR Tutorials hope this AVR C tutorial on AVR programming for digital I/O was benificial to
you and looks forward to your next visit.