This is a simple blinking LED program. We will look at basic structure and cover specifics about the syntax. First let’s talk about the files that surround the main document you created. These are called “includes” and they bring code into the main document. This code adds or augments the functionality of your code. Includes can be found in the WinAvr folder and in the current project folder. This include is outside the project folder and uses the <> around the name #include <avr/io.h> Schematic Program /*********************************************************** Program : LED Blink. Software: IDE: Atmel Studio 4 Compiler: avr-gcc Microcontroller - Atmega 16 Port B : LED Copyright (C) 2014 - 2016 H.E.A.R.T. Tech Solutions, India. ************************************************************/ #include<avr/io.h> #include<util/delay.h> void main() { DDRB=0b1111111; // PORT B All Bits Declared
AVR is 8 bit microcontroller. All its ports are 8 bit wide. Every port has 3 registers associated with it each one with 8 bits. Every bit in those registers configure pins of particular port. Bit0 of these registers is associated with Pin0 of the port, Bit1 of these registers is associated with Pin1 of the port, …. and like wise for other bits. These three registers are as follows : (x can be replaced by A,B,C,D as per the AVR you are using) – DDRx register – PORTx register – PINx register DDRx (Data Direction Register) configures data direction of port pins. Means its setting determines whether port pins will be used for input or output. Writing 0 to a bit in DDRx makes corresponding port pin as input, while writing 1 to a bit in DDRx makes corresponding port pin as output. example: to make all pins of port A as input pins : DDRA = 0b00000000; to make all pins of port A as output pins : DDRA = 0b11111111; to make lower nibble of port B as output and