]> mj.ucw.cz Git - misc.git/blob - tenar/tenar.c
Waking up Ogion using ATtiny
[misc.git] / tenar / tenar.c
1 /*
2  *      Waking Up Ogion
3  *
4  *      (c) 2013 Martin Mares <mj@ucw.cz>
5  */
6
7 /*
8  *      Pin assignment (component side view; "*" marks inverted signals)
9  *
10  *                      +-------------------+
11  *                      | RESET*        VCC |
12  *      output RESET*   | PB3           SCK |
13  *      diagnostic LED* | PB4          MISO |
14  *                      | GND          MOSI |
15  *                      +-------------------+
16  */
17
18 #define F_CPU 1200000UL
19
20 #include <avr/io.h>
21 #include <avr/sleep.h>
22 #include <util/delay.h>
23
24 typedef uint8_t byte;
25
26 #define B(x) (1U<<(x))
27
28 static void sleep(uint16_t millisec)
29 {
30         while (millisec) {
31                 _delay_ms(1);
32                 millisec--;
33         }
34 }
35
36 int main(void)
37 {
38         PORTB &= ~B(PB3);               // PB3: tri-stated
39         DDRB |= B(PB4);                 // PB4: output
40
41         for (byte i=0; i<5; i++) {
42                 PORTB &= ~B(PB4);
43                 sleep(100);
44                 PORTB |= B(PB4);
45                 sleep(900);
46         }
47
48         PORTB &= ~B(PB4);
49         DDRB |= B(PB3);                 // PB3: output 0
50         sleep(300);
51         DDRB &= ~B(PB3);                // PB3: tri-state
52         PORTB |= B(PB4);
53
54         for (;;) {
55                 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
56                 sleep_mode();
57         }
58 }