Rev 342 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
310 | pangu | 1 | /* |
2 | * Blitzdings main.c |
||
3 | * (c) pangu |
||
4 | */ |
||
311 | pangu | 5 | |
6 | /******************************************************************/ |
||
7 | /* WICHTIG: Fusebits in Ponyprog für 8MHz setzen: |
||
8 | |||
9 | Häkchen in Ponyprog: |
||
10 | CKSEL3 gesetzt |
||
11 | CKSEL2 nicht gesetzt |
||
12 | CKSEL1 gesetzt |
||
13 | CKSEL0 gesetzt |
||
14 | |||
15 | */ |
||
16 | /******************************************************************/ |
||
310 | pangu | 17 | |
18 | #include "main.h" |
||
19 | #include "timer.h" |
||
20 | #include "lprg.h" |
||
21 | |||
22 | /* Strings zum definieren von Dauer-Ein Dauer-Aus */ |
||
23 | const char l_on[]="A"; |
||
24 | const char l_off[]="a"; |
||
25 | |||
26 | // Wait flags: |
||
27 | // . 10 ms |
||
28 | // : 20 ms |
||
29 | // ; 50 ms |
||
30 | // I 100 ms |
||
31 | // N 200 ms |
||
32 | // M 300 ms |
||
33 | // V 500 ms |
||
34 | // S 1s |
||
35 | // LED: |
||
36 | // A-an a-aus |
||
37 | |||
38 | // Rot+Grün blitzen dreimal kurz, zeitlich leicht versetzt, alle 1,5s |
||
39 | // 2 weisse und 2 blaue LEDs sind an und gehen alle 3s reihum kurz aus |
||
312 | pangu | 40 | char *led_posflash1[] = { |
310 | pangu | 41 | "A:aIA:aIA:aSV", // LED #1 rot |
42 | ".", // LED #2 |
||
43 | "NNaIASSNNN", // LED #3 blau |
||
44 | ".", // LED #4 |
||
45 | "NaIASSNNNN", // LED #5 weiss |
||
46 | "NA:aIA:aIA:aMS", // LED #6 grün |
||
47 | ".", // LED #7 |
||
48 | "aIASSNNNNN", // LED #8 weiss |
||
49 | ".", // LED #9 |
||
50 | "NNNaIASSNN" // LED #10 blau |
||
51 | }; |
||
52 | |||
312 | pangu | 53 | // dasselbe, nur sind w/b dauer-an |
54 | char *led_posflash[] = { |
||
341 | pangu | 55 | "A", // LED #1 rot |
56 | "A", // LED #2 |
||
312 | pangu | 57 | "A", // LED #3 blau |
341 | pangu | 58 | "A", // LED #4 |
470 | pangu | 59 | "A;aIA;aIA;aSV", // LED #5 weiss |
60 | "NA;aIA;aIA;aMS", // LED #6 grün |
||
341 | pangu | 61 | "A", // LED #7 |
312 | pangu | 62 | "A", // LED #8 weiss |
341 | pangu | 63 | "A", // LED #9 |
312 | pangu | 64 | "A" // LED #10 blau |
65 | }; |
||
310 | pangu | 66 | |
312 | pangu | 67 | |
310 | pangu | 68 | char *led_aus[] = { |
69 | l_off, // LED #1 rot |
||
70 | l_off, // LED #2 blau |
||
71 | l_off, // LED #3 blau |
||
72 | l_off, // LED #4 |
||
73 | l_off, // LED #5 weiss |
||
74 | l_off, // LED #6 grün |
||
75 | l_off, // LED #7 |
||
76 | l_off, // LED #8 weiss |
||
77 | l_off, // LED #9 |
||
78 | l_off // LED #10 |
||
79 | }; |
||
80 | |||
81 | char *led_an[] = { |
||
82 | l_on, // LED #1 rot |
||
83 | l_on, // LED #2 blau |
||
84 | l_on, // LED #3 blau |
||
85 | l_on, // LED #4 |
||
86 | l_on, // LED #5 weiss |
||
87 | l_on, // LED #6 grün |
||
88 | l_on, // LED #7 |
||
89 | l_on, // LED #8 weiss |
||
90 | l_on, // LED #9 |
||
91 | l_on // LED #10 |
||
92 | }; |
||
93 | |||
94 | // alle LEDs toggeln synchron, 300ms Leucht/Aus-Dauer |
||
95 | char *led_flash1[] = { |
||
96 | "aMAM", // LED #1 rot |
||
97 | "aMAM", // LED #2 blau |
||
98 | "aMAM", // LED #3 blau |
||
99 | "aMAM", // LED #4 |
||
100 | "aMAM", // LED #5 weiss |
||
101 | "aMAM", // LED #6 grün |
||
102 | "aMAM", // LED #7 |
||
103 | "aMAM", // LED #8 weiss |
||
104 | "aMAM", // LED #9 |
||
105 | "aMAM" // LED #10 |
||
106 | }; |
||
107 | |||
312 | pangu | 108 | // low Volatage Warning: alle LEDs toggeln synchron, 100ms Leucht/Aus-Dauer |
109 | char *led_lowVolt[] = { |
||
110 | "aIAI", // LED #1 rot |
||
111 | "aIAI", // LED #2 blau |
||
112 | "aIAI", // LED #3 blau |
||
113 | "aIAI", // LED #4 |
||
114 | "aIAI", // LED #5 weiss |
||
115 | "aIAI", // LED #6 grün |
||
116 | "aIAI", // LED #7 |
||
117 | "aIAI", // LED #8 weiss |
||
118 | "aIAI", // LED #9 |
||
119 | "aIAI" // LED #10 |
||
120 | }; |
||
121 | |||
310 | pangu | 122 | // alle LEDs toggeln mit verschiednen Zykluszeiten |
123 | char *led_flash2[] = { |
||
470 | pangu | 124 | "ASIIaIAIaIaV", // LED #1 |
125 | "ASIIaIAIaIaV", // LED #2 |
||
126 | "aSIIIAIaIIIIAIaI", // LED #3 |
||
127 | "aSIIIAIaIIIAIaII", // LED #4 |
||
128 | "aSIIIAIaIIAIaIII", // LED #5 |
||
129 | "aVSIAIaIII", // LED #6 |
||
130 | "aSIIIAIaIIIAIaII", // LED #7 |
||
131 | "aSIIIAIaIIIIAIaI", // LED #8 |
||
132 | "aSIIIAIaI IIII AI", // LED #9 |
||
133 | "aSIIIAIaI IIII AI" // LED #10 |
||
310 | pangu | 134 | }; |
135 | |||
136 | |||
137 | // Hier die zu verwendenden LichtProgramme einfach eintragen. |
||
138 | |||
312 | pangu | 139 | int current = 0; |
341 | pangu | 140 | |
470 | pangu | 141 | void *modes[]= { led_an, led_aus, led_posflash, led_flash2 }; |
312 | pangu | 142 | |
341 | pangu | 143 | void nextMode(void) { |
310 | pangu | 144 | |
312 | pangu | 145 | current = ++current % (sizeof(modes)/sizeof(void *)); |
310 | pangu | 146 | lprg_init(modes[current]); |
312 | pangu | 147 | |
310 | pangu | 148 | } |
149 | |||
150 | ISR(INT1_vect) |
||
151 | { |
||
152 | |||
153 | nextMode(); |
||
154 | |||
155 | } |
||
156 | |||
157 | |||
341 | pangu | 158 | int main(void) { |
310 | pangu | 159 | |
341 | pangu | 160 | int tim1s, tim3s, tim10s, analog_state=0; |
470 | pangu | 161 | int Vcurr, lowVwarn_on = 0; |
310 | pangu | 162 | |
341 | pangu | 163 | SFIOR = 0x00; // Analog Comperator aus |
164 | ADCSRA = 0xD3; // Converter ein, single |
||
165 | |||
310 | pangu | 166 | // Ports einstellen |
167 | // Pin B |7|6|5|4|3|2|1|0 |
||
168 | // Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h) |
||
169 | // Pin B0 und B2 als Ausgänge festlegen |
||
170 | DDRB = 0x05; |
||
171 | |||
172 | // Pin C |7|6|5|4|3|2|1|0 |
||
173 | // Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h) |
||
174 | // Pin C1 bis C5 als Ausgänge festlegen |
||
175 | DDRC = 0x3E; |
||
176 | |||
177 | // Pin D |7|6|5|4|3|2|1|0 |
||
178 | // Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h) |
||
179 | DDRD = 0xF0; |
||
180 | //Pullup für PD3 aktivieren |
||
181 | PORTD |= (1 << PD3); |
||
182 | |||
183 | |||
184 | //interrupt konfigurueren |
||
185 | GIMSK = 1<<INT1; |
||
186 | MCUCR = 1<<ISC10; |
||
187 | |||
188 | ALLES_OFF; |
||
189 | |||
190 | STATUS_ON; |
||
191 | |||
192 | Timer_Init(); |
||
312 | pangu | 193 | |
194 | lprg_init(modes[current]); |
||
470 | pangu | 195 | tim10s = SetDelay(20000); |
312 | pangu | 196 | tim3s = SetDelay(3000); |
310 | pangu | 197 | tim1s = SetDelay(1000); |
198 | |||
312 | pangu | 199 | |
310 | pangu | 200 | sei(); //interrupts einschalten |
201 | |||
202 | while (1) { |
||
203 | |||
204 | if(flag10ms) { // every 10ms |
||
341 | pangu | 205 | flag10ms = 0; |
206 | lprg_step(); // next step in light prog |
||
207 | |||
208 | if(!analog_state) { // Sampling der SPannung starten |
||
209 | ADMUX = 0 | 0xC0; // Kanal 0, interne Referenz |
||
210 | ADCSRA |= 0x10; // Ready löschen |
||
211 | ADCSRA |= 0x40; // Start |
||
212 | analog_state++; // erst wieder sampeln, wenn der Wert ausgelesen wurde |
||
213 | } |
||
214 | |||
310 | pangu | 215 | } |
216 | |||
312 | pangu | 217 | // 1s-Task: Status-LED toggeln, Spannung checken |
218 | if(CheckDelay(tim1s)) { |
||
341 | pangu | 219 | if (ADCSRA & 0x10) { // Spannungs-Messung beendet? |
220 | ADCSRA = 0xD3; |
||
221 | Vcurr = ADCW; // Wert merken |
||
222 | analog_state = 0; |
||
223 | } |
||
312 | pangu | 224 | if(Vcurr < 180) { |
341 | pangu | 225 | lprg_init(led_lowVolt); |
470 | pangu | 226 | lowVwarn_on = 1; |
312 | pangu | 227 | } |
470 | pangu | 228 | if(lowVwarn_on && Vcurr>=180) { |
341 | pangu | 229 | lprg_init(modes[current]); |
470 | pangu | 230 | lowVwarn_on = 0; |
341 | pangu | 231 | } |
310 | pangu | 232 | STATUS_TOGGLE; |
233 | tim1s = SetDelay(1000); |
||
234 | } |
||
312 | pangu | 235 | |
236 | // 3s-Task: Unterspannungswarnung ggf. zurücknehmen |
||
237 | if(CheckDelay(tim3s)) { |
||
341 | pangu | 238 | |
312 | pangu | 239 | tim3s = SetDelay(3000); |
240 | } |
||
241 | |||
242 | // 10s-Task: DEMO: programm wechseln |
||
243 | if(CheckDelay(tim10s)) { |
||
342 | pangu | 244 | nextMode(); |
312 | pangu | 245 | tim10s = SetDelay(10000); |
246 | } |
||
247 | |||
248 | |||
249 | |||
310 | pangu | 250 | } |
251 | |||
252 | } |
||
253 | |||
254 | |||
255 | |||
256 | |||
257 |