Rev 51 | Rev 53 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 51 | Rev 52 | ||
---|---|---|---|
Line 22... | Line 22... | ||
22 | volatile unsigned char ch1; |
22 | volatile unsigned char ch1; |
23 | volatile unsigned char ch2; |
23 | volatile unsigned char ch2; |
24 | volatile unsigned char ch3; |
24 | volatile unsigned char ch3; |
25 | volatile unsigned char ch4; |
25 | volatile unsigned char ch4; |
26 | volatile unsigned char ch5; |
26 | volatile unsigned char ch5; |
- | 27 | volatile unsigned char ch0_tmp; |
|
- | 28 | volatile unsigned char ch1_tmp; |
|
- | 29 | volatile unsigned char ch2_tmp; |
|
- | 30 | volatile unsigned char ch3_tmp; |
|
- | 31 | volatile unsigned char ch4_tmp; |
|
- | 32 | volatile unsigned char ch5_tmp; |
|
- | 33 | ||
- | 34 | ||
27 | unsigned int timer; |
35 | unsigned int timer; |
Line 28... | Line 36... | ||
28 | 36 | ||
29 | SIGNAL(SIG_OVERFLOW1) |
37 | SIGNAL(SIG_OVERFLOW1) |
30 | { |
38 | { |
Line 64... | Line 72... | ||
64 | 72 | ||
65 | 73 | ||
- | 74 | ||
- | 75 | SIGNAL(SIG_OVERFLOW0) |
|
- | 76 | { |
|
- | 77 | // this function is called every 32us, |
|
66 | 78 | // it is very important that it's execution time is as short as possible |
|
67 | SIGNAL(SIG_OVERFLOW0) |
79 | // currently it's about 20us |
68 | { |
80 | |
69 | static unsigned char counter; |
81 | static unsigned char counter = 254; |
Line 70... | Line 82... | ||
70 | static unsigned char ms1; |
82 | static unsigned char ms1 = 0; |
71 | unsigned char PORTB_BAK; |
83 | unsigned char PORTB_BAK; |
Line 72... | Line 84... | ||
72 | unsigned char PORTD_BAK; |
84 | unsigned char PORTD_BAK; |
73 | 85 | ||
74 | PORTB_BAK = PORTB; |
86 | PORTB_BAK = PORTB; |
75 | PORTD_BAK = PORTD; |
87 | PORTD_BAK = PORTD; |
- | 88 | ||
- | 89 | if (counter++ == 254) |
|
- | 90 | { |
|
- | 91 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
|
- | 92 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
|
- | 93 | ch0_tmp = ch0; |
|
76 | 94 | ch1_tmp = ch1; |
|
77 | if (counter++ == 254) |
95 | ch2_tmp = ch2; |
Line 78... | Line 96... | ||
78 | { |
96 | ch3_tmp = ch3; |
79 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
97 | ch4_tmp = ch4; |
80 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
98 | ch5_tmp = ch5; |
81 | counter = 0; |
99 | counter = 0; |
82 | } |
100 | } |
83 | 101 | ||
Line 84... | Line 102... | ||
84 | if (ch0 == counter) PORTB_BAK LEDOFF CH0_B; |
102 | if (ch0_tmp == counter) PORTB_BAK LEDOFF CH0_B; |
85 | if (ch1 == counter) PORTB_BAK LEDOFF CH1_B; |
103 | if (ch1_tmp == counter) PORTB_BAK LEDOFF CH1_B; |
Line 86... | Line 104... | ||
86 | if (ch2 == counter) PORTB_BAK LEDOFF CH2_B; |
104 | if (ch2_tmp == counter) PORTB_BAK LEDOFF CH2_B; |
Line 143... | Line 161... | ||
143 | 161 | ||
Line 144... | Line -... | ||
144 | } |
- | |
145 | 162 | } |
|
146 | 163 | ||
147 | 164 | ||
Line 148... | Line 165... | ||
148 | 165 | ||
Line 161... | Line 178... | ||
161 | 178 | ||
Line -... | Line 179... | ||
- | 179 | } |
|
162 | } |
180 | |
163 | 181 | ||
164 | 182 | ||
165 | 183 | /*##############################################################################*/ |
|
166 | int GetPPM(void) |
184 | int GetPPM(void) |
Line 186... | Line 204... | ||
186 | /*##############################################################################*/ |
204 | /*##############################################################################*/ |
187 | int main (void) |
205 | int main (void) |
188 | { |
206 | { |
189 | unsigned int i; |
207 | unsigned int i; |
190 | unsigned char colorState; |
208 | unsigned char colorState; |
191 | unsigned char nextcolorState; |
209 | unsigned char nextcolorState=0; |
Line 192... | Line 210... | ||
192 | 210 | ||
193 | DDRB = (CH0_B|CH1_B|CH2_B); |
211 | DDRB = (CH0_B|CH1_B|CH2_B); |
Line 194... | Line 212... | ||
194 | PORTB = 0x00; |
212 | PORTB = 0x00; |
Line 211... | Line 229... | ||
211 | //StartI2C(); |
229 | //StartI2C(); |
212 | StartPWM(); |
230 | StartPWM(); |
213 | sei(); |
231 | sei(); |
Line 214... | Line 232... | ||
214 | 232 | ||
Line 215... | Line 233... | ||
215 | 233 | ||
Line 216... | Line 234... | ||
216 | //rot > Violett > Blau > Türkis > Grün > Gelb > |
234 | // Farbablauf: rot > Violett > blau > tuerkis > gruen > gelb > |
Line 226... | Line 244... | ||
226 | for (i=0; i<=255; i++) |
244 | for (i=0; i<=255; i++) |
227 | { |
245 | { |
228 | switch(colorState) |
246 | switch(colorState) |
229 | { |
247 | { |
230 | case 0: |
248 | case 0: |
231 | ch0 = i; //fade in (ch0) red |
249 | ch0 = i; //fade in (ch0) red |
232 | nextcolorState = 2; |
250 | nextcolorState = 2; |
233 | break; |
251 | break; |
Line 234... | Line 252... | ||
234 | 252 | ||
235 | case 2: |
253 | case 2: |
236 | ch1 = i; //fade in (ch1) blue to get purple (red + blue) |
254 | ch1 = i; //fade in (ch1) blue to get pure purple (red + blue) |
237 | nextcolorState = 4; |
255 | nextcolorState = 4; |
Line 238... | Line 256... | ||
238 | break; |
256 | break; |
239 | 257 | ||
240 | case 4: |
258 | case 4: |
241 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
259 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
Line 242... | Line 260... | ||
242 | nextcolorState = 6; |
260 | nextcolorState = 6; |
243 | break; |
261 | break; |
244 | 262 | ||
245 | case 6: |
263 | case 6: |
Line 246... | Line 264... | ||
246 | ch2 = i; //fade in (ch2) green to get cyan (blue + green) |
264 | ch2 = i; //fade in (ch2) green to get pure cyan (blue + green) |
247 | nextcolorState = 8; |
265 | nextcolorState = 8; |
248 | break; |
266 | break; |
249 | 267 | ||
Line 250... | Line 268... | ||
250 | case 8: |
268 | case 8: |
251 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
269 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
252 | nextcolorState = 10; |
270 | nextcolorState = 10; |
253 | break; |
271 | break; |
Line 254... | Line 272... | ||
254 | 272 | ||
255 | case 10: |
273 | case 10: |
256 | ch0 = i; //fade in (ch0) red to get yellow (green + red) |
274 | ch0 = i; //fade in (ch0) red to get yellow pure (green + red) |
257 | nextcolorState = 12; |
275 | nextcolorState = 12; |
258 | break; |
276 | break; |
Line 259... | Line 277... | ||
259 | 277 | ||
260 | case 12: |
278 | case 12: |
261 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
279 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
Line 262... | Line 280... | ||
262 | nextcolorState = 0; |
280 | nextcolorState = 0; |
- | 281 | break; |
|
263 | break; |
282 | } |
264 | } |
283 | |
Line 265... | Line 284... | ||
265 | 284 | ||
Line 266... | Line 285... | ||
266 | 285 | timer = SetDelay(5); //wait 10ms |
|
- | 286 | while (!CheckDelay(timer)); |
|
- | 287 | } |
|
- | 288 | ||
- | 289 | colorState = nextcolorState; |
|
- | 290 | ||
- | 291 | timer = SetDelay(3); //hold pure colors for additional 3ms |
|
- | 292 | while (!CheckDelay(timer)); |
|
- | 293 | ||
- | 294 | ||
- | 295 | } |
|
- | 296 | ||
- | 297 | ||
- | 298 | } |
|
- | 299 | ||
- | 300 | ||
- | 301 | ||
- | 302 | /* |
|
- | 303 | 170 00fa 1F92 push __zero_reg__ |
|
- | 304 | 171 00fc 0F92 push __tmp_reg__ |
|
- | 305 | 172 00fe 0FB6 in __tmp_reg__,__SREG__ |
|
- | 306 | 173 0100 0F92 push __tmp_reg__ |
|
- | 307 | 174 0102 1124 clr __zero_reg__ |
|
- | 308 | 175 0104 2F93 push r18 |
|
- | 309 | 176 0106 3F93 push r19 |
|
- | 310 | 177 0108 8F93 push r24 |
|
- | 311 | 178 010a 9F93 push r25 |
|
- | 312 | 181 010c 38B3 in r19,56-0x20 |
|
- | 313 | 184 010e 22B3 in r18,50-0x20 |
|
- | 314 | 187 0110 8091 0000 lds r24,counter.1797 |
|
- | 315 | 188 0114 8F5F subi r24,lo8(-(1)) |
|
- | 316 | 189 0116 8093 0000 sts counter.1797,r24 |
|
- | 317 | 190 011a 8F3F cpi r24,lo8(-1) |
|
- | 318 | 191 011c 01F4 brne .L15 |
|
- | 319 | 193 011e 3E60 ori r19,lo8(14) |
|
- | 320 | 195 0120 2863 ori r18,lo8(56) |
|
- | 321 | 197 0122 8091 0000 lds r24,ch0 |
|
- | 322 | 198 0126 8093 0000 sts ch0_tmp,r24 |
|
- | 323 | 200 012a 8091 0000 lds r24,ch1 |
|
- | 324 | 201 012e 8093 0000 sts ch1_tmp,r24 |
|
- | 325 | 203 0132 8091 0000 lds r24,ch2 |
|
- | 326 | 204 0136 8093 0000 sts ch2_tmp,r24 |
|
- | 327 | 206 013a 8091 0000 lds r24,ch3 |
|
- | 328 | 207 013e 8093 0000 sts ch3_tmp,r24 |
|
- | 329 | 209 0142 8091 0000 lds r24,ch4 |
|
- | 330 | 210 0146 8093 0000 sts ch4_tmp,r24 |
|
- | 331 | 212 014a 8091 0000 lds r24,ch5 |
|
- | 332 | 213 014e 8093 0000 sts ch5_tmp,r24 |
|
- | 333 | 215 0152 1092 0000 sts counter.1797,__zero_reg__ |
|
- | 334 | 218 0156 8091 0000 lds r24,ch0_tmp |
|
- | 335 | 219 015a 9091 0000 lds r25,counter.1797 |
|
- | 336 | 220 015e 8917 cp r24,r25 |
|
- | 337 | 221 0160 01F4 brne .L17 |
|
- | 338 | 222 0162 377F andi r19,lo8(-9) |
|
- | 339 | 225 0164 8091 0000 lds r24,ch1_tmp |
|
- | 340 | 226 0168 8917 cp r24,r25 |
|
- | 341 | 227 016a 01F4 brne .L19 |
|
- | 342 | 228 016c 3B7F andi r19,lo8(-5) |
|
- | 343 | 231 016e 8091 0000 lds r24,ch2_tmp |
|
- | 344 | 232 0172 8917 cp r24,r25 |
|
- | 345 | 233 0174 01F4 brne .L21 |
|
- | 346 | 234 0176 3D7F andi r19,lo8(-3) |
|
- | 347 | 237 0178 8091 0000 lds r24,ch3_tmp |
|
- | 348 | 238 017c 8917 cp r24,r25 |
|
- | 349 | 239 017e 01F4 brne .L23 |
|
- | 350 | 240 0180 277F andi r18,lo8(-9) |
|
- | 351 | 243 0182 8091 0000 lds r24,ch4_tmp |
|
- | 352 | 244 0186 8917 cp r24,r25 |
|
- | 353 | 245 0188 01F4 brne .L25 |
|
- | 354 | 246 018a 2F7E andi r18,lo8(-17) |
|
- | 355 | 249 018c 8091 0000 lds r24,ch5_tmp |
|
- | 356 | 250 0190 8917 cp r24,r25 |
|
- | 357 | 251 0192 01F4 brne .L27 |
|
- | 358 | 252 0194 2F7D andi r18,lo8(-33) |
|
- | 359 | 255 0196 38BB out 56-0x20,r19 |
|
- | 360 | 257 0198 22BB out 50-0x20,r18 |
|
- | 361 | 259 019a 8091 0000 lds r24,ms1.1798 |
|
- | 362 | 260 019e 8F5F subi r24,lo8(-(1)) |
|
- | 363 | 261 01a0 8093 0000 sts ms1.1798,r24 |
|
- | 364 | 262 01a4 8132 cpi r24,lo8(33) |
|
- | 365 | 263 01a6 01F4 brne .L31 |
|
- | 366 | 265 01a8 1092 0000 sts ms1.1798,__zero_reg__ |
|
- | 367 | 267 01ac 8091 0000 lds r24,TMR1MS |
|
- | 368 | 268 01b0 9091 0000 lds r25,(TMR1MS)+1 |