From a42490b6e32cecc691f7824b68e8b941661a1e74 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Fri, 23 Aug 2013 16:21:49 +0200 Subject: [PATCH] Waking up Ogion using ATtiny --- tenar/Makefile | 22 +++++++++++++++++++ tenar/tenar.c | 58 ++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 80 insertions(+) create mode 100644 tenar/Makefile create mode 100644 tenar/tenar.c diff --git a/tenar/Makefile b/tenar/Makefile new file mode 100644 index 0000000..a557ff1 --- /dev/null +++ b/tenar/Makefile @@ -0,0 +1,22 @@ +all: tenar.flash + +GCF=-Os -mmcu=attiny13 -std=gnu99 -Wall -W -Wno-parentheses + +%.flash: %.hex + scp $< abacus:avr/tmp/ + ssh root@abacus 'cd ~mj/avr/bin && ./avrdude -p t13 -c dapa -v -U flash:w:../tmp/$<: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/tenar/tenar.c b/tenar/tenar.c new file mode 100644 index 0000000..d69c0ad --- /dev/null +++ b/tenar/tenar.c @@ -0,0 +1,58 @@ +/* + * Waking Up Ogion + * + * (c) 2013 Martin Mares + */ + +/* + * Pin assignment (component side view; "*" marks inverted signals) + * + * +-------------------+ + * | RESET* VCC | + * output RESET* | PB3 SCK | + * diagnostic LED* | PB4 MISO | + * | GND MOSI | + * +-------------------+ + */ + +#define F_CPU 1200000UL + +#include +#include +#include + +typedef uint8_t byte; + +#define B(x) (1U<<(x)) + +static void sleep(uint16_t millisec) +{ + while (millisec) { + _delay_ms(1); + millisec--; + } +} + +int main(void) +{ + PORTB &= ~B(PB3); // PB3: tri-stated + DDRB |= B(PB4); // PB4: output + + for (byte i=0; i<5; i++) { + PORTB &= ~B(PB4); + sleep(100); + PORTB |= B(PB4); + sleep(900); + } + + PORTB &= ~B(PB4); + DDRB |= B(PB3); // PB3: output 0 + sleep(300); + DDRB &= ~B(PB3); // PB3: tri-state + PORTB |= B(PB4); + + for (;;) { + set_sleep_mode(SLEEP_MODE_PWR_DOWN); + sleep_mode(); + } +} -- 2.39.2