summaryrefslogtreecommitdiff
path: root/Example01
diff options
context:
space:
mode:
authorNathan Ringo <nathan@remexre.com>2024-02-26 00:46:09 -0600
committerNathan Ringo <nathan@remexre.com>2024-02-26 00:46:09 -0600
commitfec505240f22065aaea2ee80c1082cad136559bb (patch)
treec5154ef52e8792b9470957332caeedb925604012 /Example01
Initial commitHEADtrunk
Diffstat (limited to 'Example01')
-rw-r--r--Example01/Makefile10
-rw-r--r--Example01/main.c14
2 files changed, 24 insertions, 0 deletions
diff --git a/Example01/Makefile b/Example01/Makefile
new file mode 100644
index 0000000..6ad5610
--- /dev/null
+++ b/Example01/Makefile
@@ -0,0 +1,10 @@
+all: main.hex
+
+%.hex: %.elf
+ avr-objcopy -O ihex $< $@
+%.elf: %.o crtatmega3208.o
+ avr-gcc -mmcu=atmega3208 -L../toolchain/lib -o $@ $<
+%.o: %.c
+ avr-gcc -c -D__AVR_DEV_LIB_NAME__=m3208 -I../toolchain/include -mmcu=atmega3208 -O3 -o $@ $<
+crtatmega3208.o: ../toolchain/lib/crtatmega3208.o
+ cp --reflink=auto $< $@
diff --git a/Example01/main.c b/Example01/main.c
new file mode 100644
index 0000000..76a47b2
--- /dev/null
+++ b/Example01/main.c
@@ -0,0 +1,14 @@
+#define F_CPU 3333333
+#include <avr/io.h>
+#include <stdbool.h>
+
+int main(void) {
+ PORTF.DIR &= ~PIN3_bm; // button as input
+ PORTF.DIR |= PIN4_bm; // green as output
+ PORTF.DIR |= PIN5_bm; // red as output
+
+ while (1) {
+ bool buttonp = PORTF.IN & PIN3_bm;
+ PORTF.OUT = 1 << (buttonp ? PIN4_bp : PIN5_bp);
+ }
+}