diff --git a/Makefile b/Makefile new file mode 100644 index 0000000000000000000000000000000000000000..c3911880608deb877e984be9c9b04d98c96f947c --- /dev/null +++ b/Makefile @@ -0,0 +1,8 @@ +leds.hex: leds.o + avr-objcopy -j .text -j .data -O ihex leds.o leds.hex + +leds.o: + avr-gcc leds.c -o leds.o -Wall -Wextra -Wpedantic -mmcu=atmega328p -Os -std=c99 + +flash: + avrdude -p atmega328p -c gpio -U flash:w:leds.hex diff --git a/leds.c b/leds.c index 356218e9fd2aeb971c04435b8fef8cc67840a884..76fb97d080a5ef875a6966522a8a46e3b776d42a 100644 --- a/leds.c +++ b/leds.c @@ -4,13 +4,27 @@ #include<avr/io.h> int main(void){ - DDRD = 0b00111111; - DDRB = 0b11111100; - PORTD = 0b00000000; + DDRD = 0b11111100; + DDRB = 0b00111111; + PORTD = 0b00000011; PORTB = 0b00000000; + char on = 0; while(1){ - if(PORTD != 0b11111111) PORTD = PORTD<<1+1; - if(PORTB != 0b11111111) PORTB = PORTB<<1+1; - _delay_ms(1000); + while(!on){ + if(PORTD != 0b11111111) PORTD = (PORTD<<1)+1; + else{ + if(PORTB != 0b11111111) PORTB = (PORTB<<1)+1; + else on=1; + } + _delay_ms(250); + } + while(on){ + if(PORTB != 0b00000000) PORTB = (PORTB-1)>>1; + else{ + if(PORTD != 0b00000011) PORTD = (PORTD-1)>>1; + else on=0; + } + _delay_ms(250); + } } -} \ No newline at end of file +}