From a18aefd421605d6ab3beae90bd82da5fe8afc15d Mon Sep 17 00:00:00 2001 From: Julia Wichmann <Julia.Wichmann@s2017.tu-chemnitz.de> Date: Fri, 1 Nov 2019 14:11:39 +0100 Subject: [PATCH] copy leds.c+makefile to speedyleds --- speedyleds/Makefile | 8 ++++++++ speedyleds/speedyleds.c | 31 +++++++++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 speedyleds/Makefile create mode 100644 speedyleds/speedyleds.c diff --git a/speedyleds/Makefile b/speedyleds/Makefile new file mode 100644 index 0000000..374e6c6 --- /dev/null +++ b/speedyleds/Makefile @@ -0,0 +1,8 @@ +speedyleds.hex: speedyleds.o + avr-objcopy -j .text -j .data -O ihex speedyleds.o speedyleds.hex + +speedyleds.o: + avr-gcc speedyleds.c -o speedyleds.o -Wall -Wextra -Wpedantic -mmcu=atmega328p -Os -std=c99 + +flash: + avrdude -p atmega328p -c gpio -U flash:w:speedyleds.hex diff --git a/speedyleds/speedyleds.c b/speedyleds/speedyleds.c new file mode 100644 index 0000000..a292693 --- /dev/null +++ b/speedyleds/speedyleds.c @@ -0,0 +1,31 @@ +#define F_CPU 12000000UL + +#include<util/delay.h> +#include<avr/io.h> +#include<avr/libc.h> + +int main(void){ + DDRD = 0b11111100; + DDRB = 0b00111111; + PORTD = 0b00000011; + PORTB = 0b00000000; + char on = 0; + while(1){ + 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); + } + } +} -- GitLab