Rev 470 | 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 | { |
||
473 | pangu | 152 | static int doubleclick = 0; |
153 | |||
154 | if(doubleclick && !CheckDelay(doubleclick)) { |
||
155 | nextMode(); |
||
156 | } |
||
310 | pangu | 157 | |
473 | pangu | 158 | doubleclick = SetDelay(1000); |
310 | pangu | 159 | |
160 | } |
||
161 | |||
162 | |||
341 | pangu | 163 | int main(void) { |
310 | pangu | 164 | |
341 | pangu | 165 | int tim1s, tim3s, tim10s, analog_state=0; |
470 | pangu | 166 | int Vcurr, lowVwarn_on = 0; |
310 | pangu | 167 | |
341 | pangu | 168 | SFIOR = 0x00; // Analog Comperator aus |
169 | ADCSRA = 0xD3; // Converter ein, single |
||
170 | |||
310 | pangu | 171 | // Ports einstellen |
172 | // Pin B |7|6|5|4|3|2|1|0 |
||
173 | // Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h) |
||
174 | // Pin B0 und B2 als Ausgänge festlegen |
||
175 | DDRB = 0x05; |
||
176 | |||
177 | // Pin C |7|6|5|4|3|2|1|0 |
||
178 | // Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h) |
||
179 | // Pin C1 bis C5 als Ausgänge festlegen |
||
180 | DDRC = 0x3E; |
||
181 | |||
182 | // Pin D |7|6|5|4|3|2|1|0 |
||
183 | // Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h) |
||
184 | DDRD = 0xF0; |
||
185 | //Pullup für PD3 aktivieren |
||
186 | PORTD |= (1 << PD3); |
||
187 | |||
188 | |||
189 | //interrupt konfigurueren |
||
190 | GIMSK = 1<<INT1; |
||
191 | MCUCR = 1<<ISC10; |
||
192 | |||
193 | ALLES_OFF; |
||
194 | |||
195 | STATUS_ON; |
||
196 | |||
197 | Timer_Init(); |
||
312 | pangu | 198 | |
199 | lprg_init(modes[current]); |
||
470 | pangu | 200 | tim10s = SetDelay(20000); |
312 | pangu | 201 | tim3s = SetDelay(3000); |
310 | pangu | 202 | tim1s = SetDelay(1000); |
203 | |||
312 | pangu | 204 | |
310 | pangu | 205 | sei(); //interrupts einschalten |
206 | |||
207 | while (1) { |
||
208 | |||
209 | if(flag10ms) { // every 10ms |
||
341 | pangu | 210 | flag10ms = 0; |
211 | lprg_step(); // next step in light prog |
||
212 | |||
213 | if(!analog_state) { // Sampling der SPannung starten |
||
214 | ADMUX = 0 | 0xC0; // Kanal 0, interne Referenz |
||
215 | ADCSRA |= 0x10; // Ready löschen |
||
216 | ADCSRA |= 0x40; // Start |
||
217 | analog_state++; // erst wieder sampeln, wenn der Wert ausgelesen wurde |
||
218 | } |
||
219 | |||
310 | pangu | 220 | } |
221 | |||
312 | pangu | 222 | // 1s-Task: Status-LED toggeln, Spannung checken |
223 | if(CheckDelay(tim1s)) { |
||
341 | pangu | 224 | if (ADCSRA & 0x10) { // Spannungs-Messung beendet? |
225 | ADCSRA = 0xD3; |
||
226 | Vcurr = ADCW; // Wert merken |
||
227 | analog_state = 0; |
||
228 | } |
||
312 | pangu | 229 | if(Vcurr < 180) { |
341 | pangu | 230 | lprg_init(led_lowVolt); |
470 | pangu | 231 | lowVwarn_on = 1; |
312 | pangu | 232 | } |
470 | pangu | 233 | if(lowVwarn_on && Vcurr>=180) { |
341 | pangu | 234 | lprg_init(modes[current]); |
470 | pangu | 235 | lowVwarn_on = 0; |
341 | pangu | 236 | } |
310 | pangu | 237 | STATUS_TOGGLE; |
238 | tim1s = SetDelay(1000); |
||
239 | } |
||
312 | pangu | 240 | |
241 | // 3s-Task: Unterspannungswarnung ggf. zurücknehmen |
||
242 | if(CheckDelay(tim3s)) { |
||
341 | pangu | 243 | |
312 | pangu | 244 | tim3s = SetDelay(3000); |
245 | } |
||
246 | |||
247 | // 10s-Task: DEMO: programm wechseln |
||
248 | if(CheckDelay(tim10s)) { |
||
342 | pangu | 249 | nextMode(); |
312 | pangu | 250 | tim10s = SetDelay(10000); |
251 | } |
||
252 | |||
253 | |||
254 | |||
310 | pangu | 255 | } |
256 | |||
257 | } |
||
258 | |||
259 | |||
260 | |||
261 | |||
262 |