Rev 311 | Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | pangu | 1 | /* |
2 | * Blitzdings main.c |
||
3 | * (c) pangu |
||
4 | */ |
||
5 | |||
6 | |||
7 | #include "main.h" |
||
8 | #include "timer.h" |
||
9 | #include "lprg.h" |
||
10 | |||
11 | /* Strings zum definieren von Dauer-Ein Dauer-Aus */ |
||
12 | const char l_on[]="A"; |
||
13 | const char l_off[]="a"; |
||
14 | |||
15 | // Wait flags: |
||
16 | // . 10 ms |
||
17 | // : 20 ms |
||
18 | // ; 50 ms |
||
19 | // I 100 ms |
||
20 | // N 200 ms |
||
21 | // M 300 ms |
||
22 | // V 500 ms |
||
23 | // S 1s |
||
24 | // LED: |
||
25 | // A-an a-aus |
||
26 | |||
27 | // Rot+Grün blitzen dreimal kurz, zeitlich leicht versetzt, alle 1,5s |
||
28 | // 2 weisse und 2 blaue LEDs sind an und gehen alle 3s reihum kurz aus |
||
29 | char *led_posflash[] = { |
||
30 | "A:aIA:aIA:aSV", // LED #1 rot |
||
31 | ".", // LED #2 |
||
32 | "NNaIASSNNN", // LED #3 blau |
||
33 | ".", // LED #4 |
||
34 | "NaIASSNNNN", // LED #5 weiss |
||
35 | "NA:aIA:aIA:aMS", // LED #6 grün |
||
36 | ".", // LED #7 |
||
37 | "aIASSNNNNN", // LED #8 weiss |
||
38 | ".", // LED #9 |
||
39 | "NNNaIASSNN" // LED #10 blau |
||
40 | }; |
||
41 | |||
42 | |||
43 | char *led_aus[] = { |
||
44 | l_off, // LED #1 rot |
||
45 | l_off, // LED #2 blau |
||
46 | l_off, // LED #3 blau |
||
47 | l_off, // LED #4 |
||
48 | l_off, // LED #5 weiss |
||
49 | l_off, // LED #6 grün |
||
50 | l_off, // LED #7 |
||
51 | l_off, // LED #8 weiss |
||
52 | l_off, // LED #9 |
||
53 | l_off // LED #10 |
||
54 | }; |
||
55 | |||
56 | char *led_an[] = { |
||
57 | l_on, // LED #1 rot |
||
58 | l_on, // LED #2 blau |
||
59 | l_on, // LED #3 blau |
||
60 | l_on, // LED #4 |
||
61 | l_on, // LED #5 weiss |
||
62 | l_on, // LED #6 grün |
||
63 | l_on, // LED #7 |
||
64 | l_on, // LED #8 weiss |
||
65 | l_on, // LED #9 |
||
66 | l_on // LED #10 |
||
67 | }; |
||
68 | |||
69 | // alle LEDs toggeln synchron, 300ms Leucht/Aus-Dauer |
||
70 | char *led_flash1[] = { |
||
71 | "aMAM", // LED #1 rot |
||
72 | "aMAM", // LED #2 blau |
||
73 | "aMAM", // LED #3 blau |
||
74 | "aMAM", // LED #4 |
||
75 | "aMAM", // LED #5 weiss |
||
76 | "aMAM", // LED #6 grün |
||
77 | "aMAM", // LED #7 |
||
78 | "aMAM", // LED #8 weiss |
||
79 | "aMAM", // LED #9 |
||
80 | "aMAM" // LED #10 |
||
81 | }; |
||
82 | |||
83 | // alle LEDs toggeln mit verschiednen Zykluszeiten |
||
84 | char *led_flash2[] = { |
||
85 | "a.A.", // LED #1 rot |
||
86 | "a:A:", // LED #2 blau |
||
87 | "a;A;", // LED #3 blau |
||
88 | "aIAI", // LED #4 |
||
89 | "aNAN", // LED #5 weiss |
||
90 | "aMAM", // LED #6 grün |
||
91 | "aMIAMI", // LED #7 |
||
92 | "aVAV", // LED #8 weiss |
||
93 | "aVIAVI", // LED #9 |
||
94 | "aSAS" // LED #10 |
||
95 | }; |
||
96 | |||
97 | |||
98 | // Hier die zu verwendenden LichtProgramme einfach eintragen. |
||
99 | void *modes[]= { led_an, led_posflash, led_aus, led_flash1, led_flash2 }; |
||
100 | |||
101 | void nextMode() { |
||
102 | |||
103 | static int current = 0; |
||
104 | |||
105 | lprg_init(modes[current]); |
||
106 | current = ++current % (sizeof(modes)/sizeof(void *)); |
||
107 | |||
108 | } |
||
109 | |||
110 | ISR(INT1_vect) |
||
111 | { |
||
112 | |||
113 | nextMode(); |
||
114 | |||
115 | } |
||
116 | |||
117 | |||
118 | |||
119 | int main() { |
||
120 | |||
121 | int tim10s, tim1s; |
||
122 | |||
123 | // Ports einstellen |
||
124 | // Pin B |7|6|5|4|3|2|1|0 |
||
125 | // Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h) |
||
126 | // Pin B0 und B2 als Ausgänge festlegen |
||
127 | DDRB = 0x05; |
||
128 | |||
129 | // Pin C |7|6|5|4|3|2|1|0 |
||
130 | // Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h) |
||
131 | // Pin C1 bis C5 als Ausgänge festlegen |
||
132 | DDRC = 0x3E; |
||
133 | |||
134 | // Pin D |7|6|5|4|3|2|1|0 |
||
135 | // Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h) |
||
136 | DDRD = 0xF0; |
||
137 | //Pullup für PD3 aktivieren |
||
138 | PORTD |= (1 << PD3); |
||
139 | |||
140 | |||
141 | //interrupt konfigurueren |
||
142 | GIMSK = 1<<INT1; |
||
143 | MCUCR = 1<<ISC10; |
||
144 | |||
145 | ALLES_OFF; |
||
146 | |||
147 | STATUS_ON; |
||
148 | |||
149 | Timer_Init(); |
||
150 | nextMode(); |
||
151 | tim10s = SetDelay(10000); |
||
152 | tim1s = SetDelay(1000); |
||
153 | |||
154 | sei(); //interrupts einschalten |
||
155 | |||
156 | while (1) { |
||
157 | |||
158 | if(flag10ms) { // every 10ms |
||
159 | flag10ms = 0; |
||
160 | lprg_step(); // next step in light prog |
||
161 | } |
||
162 | |||
163 | if(CheckDelay(tim10s)) { // alle 10 sec programm wechseln |
||
164 | nextMode(); |
||
165 | tim10s = SetDelay(10000); |
||
166 | } |
||
167 | if(CheckDelay(tim1s)) { // alle 1 sec STatus-LED toggeln |
||
168 | STATUS_TOGGLE; |
||
169 | tim1s = SetDelay(1000); |
||
170 | } |
||
171 | } |
||
172 | |||
173 | } |
||
174 | |||
175 | |||
176 | |||
177 | |||
178 |