DEV Community

SUNG CHUL
SUNG CHUL

Posted on

Blink an LED v.2

#define F_CPU 16000000L
#include <avr/io.h>
#include <util/delay.h>


int main(void)
{
    DDRB |= 0x0F;   // xxxx1111

    PORTB = 0x01;
    while (1)
    {   
        while (PORTB != 0x08) {
            _delay_ms(500);
            PORTB = PORTB << 1;
        }

        while (PORTB != 0x01) {
            _delay_ms(500);
            PORTB = PORTB >> 1;
        }       
    }
}
Enter fullscreen mode Exit fullscreen mode

Image description

Easy

Top comments (0)