Home   LED Flashing


AVR Sample code for LED Flashing

Sample code for AVR ATmega16.



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

#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif

#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif



int main(void)
{

    sbi(DDRD,1);

    while(1)
    {
        sbi(PORTD,1);         //This will turn ON LED
        _delay_ms(4000);

        cbi(PORTD,1);         //This will turn OFF LED
        _delay_ms(4000);
    }
    return 0;
}