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