Rev 311 | Rev 341 | 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[] = { |
||
56 | "A:aIA:aIA:aSV", // LED #1 rot |
||
57 | ".", // LED #2 |
||
58 | "A", // LED #3 blau |
||
59 | ".", // LED #4 |
||
60 | "A", // LED #5 weiss |
||
61 | "NA:aIA:aIA:aMS", // LED #6 grün |
||
62 | ".", // LED #7 |
||
63 | "A", // LED #8 weiss |
||
64 | ".", // LED #9 |
||
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; |
141 | void *modes[]= { led_posflash, led_an, led_aus }; |
||
142 | |||
310 | pangu | 143 | void nextMode() { |
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 | |||
158 | |||
159 | int main() { |
||
160 | |||
312 | pangu | 161 | int tim1s, tim3s, tim10s; |
162 | int Vcurr; |
||
310 | pangu | 163 | |
164 | // Ports einstellen |
||
165 | // Pin B |7|6|5|4|3|2|1|0 |
||
166 | // Binär:|0|0|0|0|0|1|0|1 (b) => #05 (h) |
||
167 | // Pin B0 und B2 als Ausgänge festlegen |
||
168 | DDRB = 0x05; |
||
169 | |||
170 | // Pin C |7|6|5|4|3|2|1|0 |
||
171 | // Binär:|0|0|1|1|1|1|1|0 (b) => #3E (h) |
||
172 | // Pin C1 bis C5 als Ausgänge festlegen |
||
173 | DDRC = 0x3E; |
||
174 | |||
175 | // Pin D |7|6|5|4|3|2|1|0 |
||
176 | // Binär:|1|1|1|1|0|0|0|0 (b) => #F0 (h) |
||
177 | DDRD = 0xF0; |
||
178 | //Pullup für PD3 aktivieren |
||
179 | PORTD |= (1 << PD3); |
||
180 | |||
181 | |||
182 | //interrupt konfigurueren |
||
183 | GIMSK = 1<<INT1; |
||
184 | MCUCR = 1<<ISC10; |
||
185 | |||
186 | ALLES_OFF; |
||
187 | |||
188 | STATUS_ON; |
||
189 | |||
190 | Timer_Init(); |
||
312 | pangu | 191 | |
192 | lprg_init(modes[current]); |
||
310 | pangu | 193 | tim10s = SetDelay(10000); |
312 | pangu | 194 | tim3s = SetDelay(3000); |
310 | pangu | 195 | tim1s = SetDelay(1000); |
196 | |||
312 | pangu | 197 | |
310 | pangu | 198 | sei(); //interrupts einschalten |
199 | |||
200 | while (1) { |
||
201 | |||
202 | if(flag10ms) { // every 10ms |
||
203 | flag10ms = 0; |
||
204 | lprg_step(); // next step in light prog |
||
205 | } |
||
206 | |||
312 | pangu | 207 | // 1s-Task: Status-LED toggeln, Spannung checken |
208 | if(CheckDelay(tim1s)) { |
||
209 | Vcurr = getVcurr(); |
||
210 | if(Vcurr < 180) { |
||
211 | lprg_init(led_lowVolt); |
||
212 | } |
||
310 | pangu | 213 | STATUS_TOGGLE; |
214 | tim1s = SetDelay(1000); |
||
215 | } |
||
312 | pangu | 216 | |
217 | // 3s-Task: Unterspannungswarnung ggf. zurücknehmen |
||
218 | if(CheckDelay(tim3s)) { |
||
219 | if(Vcurr>=180) { |
||
220 | lprg_init(modes[current]); |
||
221 | } |
||
222 | tim3s = SetDelay(3000); |
||
223 | } |
||
224 | |||
225 | // 10s-Task: DEMO: programm wechseln |
||
226 | if(CheckDelay(tim10s)) { |
||
227 | // nextMode(); |
||
228 | tim10s = SetDelay(10000); |
||
229 | } |
||
230 | |||
231 | |||
232 | |||
310 | pangu | 233 | } |
234 | |||
235 | } |
||
236 | |||
237 | |||
238 | |||
239 | |||
240 |