commit caf193f15ffc28342dbd3ff198b3f0dcd80875f0 Author: Ryan Cavicchioni Date: Sat May 15 11:20:06 2021 -0500 Add some simple AVR sketches 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; +}