From caf193f15ffc28342dbd3ff198b3f0dcd80875f0 Mon Sep 17 00:00:00 2001 From: Ryan Cavicchioni Date: Sat, 15 May 2021 11:20:06 -0500 Subject: [PATCH] Add some simple AVR sketches --- led1.c | 18 ++++++++++++++++++ led2.c | 27 +++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100644 led1.c create mode 100644 led2.c diff --git a/led1.c b/led1.c new file mode 100644 index 0000000..6234265 --- /dev/null +++ b/led1.c @@ -0,0 +1,18 @@ +#include +#include +#include + +int main(void) { + int i; + + DDRB = 0xff; + + PORTB = 0b10101010; + + for (;;) { + PORTB = PORTB ^ 0xff; + _delay_ms(1000); + } + + return 0; +} diff --git a/led2.c b/led2.c new file mode 100644 index 0000000..464ab94 --- /dev/null +++ b/led2.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#define DELAY 50 +#define BITS sizeof(PORTB) * CHAR_BIT - 1 + +int main(void) { + int i; + + DDRB = 0xff; + + PORTB = 1; + + for (;;) { + for (i = 0; i < BITS; i++) { + _delay_ms(DELAY); + PORTB = PORTB << 1; + } + for (i = BITS; i > 0; i--) { + _delay_ms(DELAY); + PORTB = PORTB >> 1; + } + } + + return 0; +}