]> mj.ucw.cz Git - misc.git/commitdiff
Sphinx: init
authorMartin Mares <mj@ucw.cz>
Sun, 12 Mar 2017 00:32:47 +0000 (01:32 +0100)
committerMartin Mares <mj@ucw.cz>
Sun, 12 Mar 2017 00:32:47 +0000 (01:32 +0100)
sphinx/Makefile [new file with mode: 0644]
sphinx/sphinx.c [new file with mode: 0644]

diff --git a/sphinx/Makefile b/sphinx/Makefile
new file mode 100644 (file)
index 0000000..bf9b8ea
--- /dev/null
@@ -0,0 +1,21 @@
+all: sphinx.flash
+
+GCF=-Os -mmcu=attiny13 -std=gnu99 -Wall -W -Wno-parentheses
+
+%.flash: %.hex
+       avrdude -p t13 -c usbtiny -v -U flash:w:$<:i
+
+%.hex: %.exe
+       avr-objcopy -j .text -j .data -O ihex $< $@
+
+%.exe: %.c
+       avr-gcc $< -o $@ $(GCF)
+
+%.s: %.c
+       avr-gcc $< -o $@ $(GCF) -S
+
+clean:
+       rm -f *~ *.o *.s *.exe *.hex
+
+.SECONDARY:
+.PHONY: all clean
diff --git a/sphinx/sphinx.c b/sphinx/sphinx.c
new file mode 100644 (file)
index 0000000..7355d0b
--- /dev/null
@@ -0,0 +1,64 @@
+/*
+ *     Asking Riddles at the Entrance to Garage
+ *
+ *     (c) 2017 Martin Mares <mj@ucw.cz>
+ */
+
+/*
+ *     Pin assignment (component side view; "*" marks inverted signals)
+ *
+ *                     +-------------------+
+ *                     | RESET*        VCC |
+ *     button          | PB3           SCK |
+ *     output          | PB4          MISO |
+ *                     | GND      PB0=MOSI |   diagnostic LED*
+ *                     +-------------------+
+ */
+
+#define F_CPU 1200000UL
+
+#include <avr/io.h>
+#include <avr/sleep.h>
+#include <util/delay.h>
+
+typedef uint8_t byte;
+
+#define B(x) (1U<<(x))
+
+static void sleep(uint16_t millisec)
+{
+       while (millisec) {
+               _delay_ms(1);
+               millisec--;
+       }
+}
+
+int main(void)
+{
+       DDRB |= B(PB0);                 // PB0: output
+       DDRB |= B(PB4);                 // PB4: output
+       PORTB &= ~B(PB3);               // PB3: input, no pullup
+
+       for (byte i=0; i<5; i++) {
+               PORTB &= ~B(PB0);
+               sleep(100);
+               PORTB |= B(PB0);
+               sleep(100);
+       }
+
+       for (;;) {
+               sleep(10);
+               if (PINB & B(PB3)) {
+                       PORTB &= ~B(PB0);
+                       PORTB |= B(PB4);
+               } else {
+                       PORTB |= B(PB0);
+                       PORTB &= ~B(PB4);
+               }
+       }
+
+       for (;;) {
+               set_sleep_mode(SLEEP_MODE_PWR_DOWN);
+               sleep_mode();
+       }
+}