First Code for AVR micro-controller

First Code for AVR micro-controller


Avr microcontrollers are easy to learn and cheap to buy. Also their software are open source. There are also some evulation boards like arduino available for them so they are easy to start with. We are using Atmega8a here to start coding.

#include <avr/io.h>
#include <util/delay.h>

int main(void)
{
  DDRC = 0xb00000001;                  //Nakes PORTC as Output
  while(1) //infinite loop
  {
    PORTC = 0xb00000001;              //Turns ON All LEDs
    _delay_ms(1000);           //1 second delay
    PORTC= 0xb00000001;              //Turns OFF All LEDs
    _delay_ms(1000);          //1 second delay
  }
}

DDRx is data direction register to make a pin input or output. As we only need last pin of the portB to be output, so we make it 1. 1=output ,0=input
Then in infinite while loop, we are making last pin high for 200ms and then low again for 200ms.




No comments:

Post a Comment

Thank you for your response.