]> mj.ucw.cz Git - misc.git/blob - tenar/tenar.c
Merge branch 'master' of git+ssh://git.ucw.cz/home/mj/GIT/misc
[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  *      diagnostic LED* | PB3           SCK |
13  *      output RESET*   | 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(PB4);               // PB4: tri-stated
39         DDRB |= B(PB3);                 // PB3: output
40
41         for (byte i=0; i<5; i++) {
42                 PORTB &= ~B(PB3);
43                 sleep(100);
44                 PORTB |= B(PB3);
45                 sleep(900);
46         }
47
48         PORTB &= ~B(PB3);
49         DDRB |= B(PB4);                 // PB4: output 0
50         sleep(300);
51         DDRB &= ~B(PB4);                // PB4: tri-state
52         DDRB &= ~B(PB3);                // PB3: tri-state to save power
53
54         for (;;) {
55                 set_sleep_mode(SLEEP_MODE_PWR_DOWN);
56                 sleep_mode();
57         }
58 }