Sunday, June 12, 2016

BLINKING A LED

Circuit diagram includes connecting a LED with resistor in series in PORTB5, its digital 13 on Aruino.

Blink LED method 1

#define F_CPU 16000000

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

int main(void)
{
   
DDRB |= (1 << PORTB5);
    while (1)
    {
PORTB |= (1 << PORTB5);
_delay_ms(200);
PORTB &= ~(1<< PORTB5);
_delay_ms(100);

    }
}

Blink LED method 2

#define F_CPU 16000000

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


int main(void)
{
    
DDRB |= (1 << PORTB5);
    while (1) 
    {

PINB |= (1 <<PINB5);
_delay_ms(100);
    }
}

1 comment: