Add some simple AVR sketches

This commit is contained in:
Ryan Cavicchioni 2021-05-15 11:20:06 -05:00
commit caf193f15f
Signed by: ryanc
GPG Key ID: 877EEDAF9245103D
2 changed files with 45 additions and 0 deletions

18
led1.c Normal file
View File

@ -0,0 +1,18 @@
#include <avr/io.h>
#include <util/delay.h>
#include <limits.h>
int main(void) {
int i;
DDRB = 0xff;
PORTB = 0b10101010;
for (;;) {
PORTB = PORTB ^ 0xff;
_delay_ms(1000);
}
return 0;
}

27
led2.c Normal file
View File

@ -0,0 +1,27 @@
#include <avr/io.h>
#include <util/delay.h>
#include <limits.h>
#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;
}