Rev 28 | Rev 52 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 28 | Rev 51 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | //############################################################################ |
1 | //############################################################################ |
2 | // - LED CTRL Main |
2 | // - PWM CTRL |
- | 3 | // - Main |
|
3 | // - ATMEGA8 mit 8MHz |
4 | // - ATMEGA8 mit 8MHz |
4 | // - Nur für den privaten Gebrauch |
5 | // - Nur für den privaten Gebrauch |
5 | // - Keine Garantie auf Fehlerfreiheit |
6 | // - Keine Garantie auf Fehlerfreiheit |
6 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
7 | // - Kommerzielle Nutzung nur mit meiner Zustimmung |
7 | // - walter Meyer @ www.freakware.de |
8 | // - walter Meyer @ www.freakware.de |
Line 14... | Line 15... | ||
14 | #include "twislave.h" |
15 | #include "twislave.h" |
Line 15... | Line 16... | ||
15 | 16 | ||
16 | volatile unsigned int ppm_signal = 1500; |
17 | volatile unsigned int ppm_signal = 1500; |
17 | volatile unsigned char ppm_new = 0; |
18 | volatile unsigned char ppm_new = 0; |
- | 19 | volatile unsigned char TMR1OvF = 0; |
|
18 | volatile unsigned char TMR1OvF = 0; |
20 | volatile unsigned int TMR1MS; |
19 | volatile unsigned char ch0; |
21 | volatile unsigned char ch0; |
20 | volatile unsigned char ch1; |
22 | volatile unsigned char ch1; |
21 | volatile unsigned char ch2; |
23 | volatile unsigned char ch2; |
22 | volatile unsigned char ch3; |
24 | volatile unsigned char ch3; |
23 | volatile unsigned char ch4; |
25 | volatile unsigned char ch4; |
24 | volatile unsigned char ch5; |
- | |
25 | - | ||
- | 26 | volatile unsigned char ch5; |
|
Line 26... | Line 27... | ||
26 | 27 | unsigned int timer; |
|
27 | 28 | ||
28 | SIGNAL(SIG_OVERFLOW1) |
29 | SIGNAL(SIG_OVERFLOW1) |
29 | { |
30 | { |
Line 64... | Line 65... | ||
64 | 65 | ||
65 | 66 | ||
66 | SIGNAL(SIG_OVERFLOW0) |
67 | SIGNAL(SIG_OVERFLOW0) |
- | 68 | { |
|
67 | { |
69 | static unsigned char counter; |
68 | static unsigned char counter; |
70 | static unsigned char ms1; |
Line 69... | Line 71... | ||
69 | unsigned char PORTB_BAK; |
71 | unsigned char PORTB_BAK; |
70 | unsigned char PORTD_BAK; |
72 | unsigned char PORTD_BAK; |
Line 71... | Line -... | ||
71 | - | ||
72 | PORTB_BAK = PORTB; |
73 | |
73 | PORTD_BAK = PORTD; |
74 | PORTB_BAK = PORTB; |
74 | 75 | PORTD_BAK = PORTD; |
|
75 | 76 | ||
- | 77 | if (counter++ == 254) |
|
76 | if (counter == 0) |
78 | { |
Line -... | Line 79... | ||
- | 79 | PORTB_BAK LEDON (CH0_B | CH1_B | CH2_B); |
|
- | 80 | PORTD_BAK LEDON (CH3_D | CH4_D | CH5_D); |
|
- | 81 | counter = 0; |
|
- | 82 | } |
|
- | 83 | ||
- | 84 | if (ch0 == counter) PORTB_BAK LEDOFF CH0_B; |
|
- | 85 | if (ch1 == counter) PORTB_BAK LEDOFF CH1_B; |
|
- | 86 | if (ch2 == counter) PORTB_BAK LEDOFF CH2_B; |
|
- | 87 | if (ch3 == counter) PORTD_BAK LEDOFF CH3_D; |
|
Line 77... | Line 88... | ||
77 | { |
88 | if (ch4 == counter) PORTD_BAK LEDOFF CH4_D; |
78 | PORTB_BAK clrbit (CH0_B | CH1_B | CH2_B); |
- | |
79 | PORTD_BAK clrbit (CH3_D | CH4_D | CH5_D); |
- | |
80 | } |
- | |
81 | - | ||
82 | 89 | if (ch5 == counter) PORTD_BAK LEDOFF CH5_D; |
|
83 | if (ch0 == 255) |
- | |
84 | { |
- | |
85 | PORTB_BAK setbit CH0_B; |
90 | |
86 | } |
- | |
87 | if (ch0 == counter) |
91 | PORTB = PORTB_BAK; |
88 | { |
92 | PORTD = PORTD_BAK; |
- | 93 | ||
Line -... | Line 94... | ||
- | 94 | if (ms1++ == 32) |
|
Line 89... | Line -... | ||
89 | PORTB_BAK setbit CH0_B; |
- | |
90 | } |
- | |
91 | if (ch0 == 0) |
- | |
92 | { |
- | |
93 | PORTB_BAK clrbit CH0_B; |
- | |
94 | } |
- | |
95 | - | ||
96 | - | ||
97 | - | ||
98 | - | ||
99 | - | ||
100 | - | ||
101 | if (ch1 == counter) |
95 | { |
102 | { |
96 | ms1=0; |
103 | PORTB_BAK setbit CH1_B; |
97 | TMR1MS++; |
104 | } |
- | |
105 | if (ch2 == counter) |
- | |
106 | { |
- | |
107 | PORTB_BAK setbit CH2_B; |
98 | } |
108 | } |
- | |
109 | if (ch3 == counter) |
- | |
110 | { |
- | |
111 | PORTD_BAK setbit CH3_D; |
- | |
112 | } |
- | |
113 | if (ch4_BAK == counter) |
- | |
114 | { |
- | |
115 | PORTD setbit CH4_D; |
- | |
Line -... | Line 99... | ||
- | 99 | ||
- | 100 | ||
- | 101 | ||
Line 116... | Line 102... | ||
116 | } |
102 | |
Line 117... | Line -... | ||
117 | if (ch5_BAK == counter) |
- | |
118 | { |
103 | } |
Line -... | Line 104... | ||
- | 104 | ||
119 | PORTD setbit CH5_D; |
105 | |
- | 106 | ||
- | 107 | unsigned int SetDelay (unsigned int t) |
|
- | 108 | { |
|
- | 109 | unsigned char temp_hi; |
|
- | 110 | unsigned char temp_lo; |
|
- | 111 | ||
Line -... | Line 112... | ||
- | 112 | temp_hi = (TMR1MS >> 8); |
|
- | 113 | temp_lo = (TMR1MS & 0xff); |
|
- | 114 | if (temp_hi != (TMR1MS >> 8)) temp_hi = (TMR1MS >> 8); |
|
Line 120... | Line 115... | ||
120 | } |
115 | |
121 | } |
116 | return(((temp_hi << 8) | temp_lo) + t + 1); |
122 | 117 | ||
123 | 118 | } |
|
124 | 119 | ||
125 | } |
120 | |
Line 126... | Line 121... | ||
126 | 121 | char CheckDelay(unsigned int t) |
|
Line 127... | Line -... | ||
127 | - | ||
128 | - | ||
129 | - | ||
130 | counter++; |
122 | { |
131 | 123 | unsigned char temp_hi; |
|
132 | PORTB = PORTB_BAK; |
124 | unsigned char temp_lo; |
Line 133... | Line 125... | ||
133 | PORTD = PORTD_BAK; |
125 | |
Line 192... | Line 184... | ||
192 | /*##############################################################################*/ |
184 | /*##############################################################################*/ |
193 | // MAIN |
185 | // MAIN |
194 | /*##############################################################################*/ |
186 | /*##############################################################################*/ |
195 | int main (void) |
187 | int main (void) |
196 | { |
188 | { |
- | 189 | unsigned int i; |
|
- | 190 | unsigned char colorState; |
|
- | 191 | unsigned char nextcolorState; |
|
Line 197... | Line -... | ||
197 | - | ||
198 | DDRC = (1<<ledred); |
- | |
199 | PORTC = 0x00; |
- | |
200 | DDRD = (1<<ledgreen); |
- | |
201 | PORTD = 0x00; |
192 | |
202 | DDRB = (1<<1)|(1<<2)|(1<<3); |
193 | DDRB = (CH0_B|CH1_B|CH2_B); |
Line -... | Line 194... | ||
- | 194 | PORTB = 0x00; |
|
- | 195 | ||
- | 196 | DDRC = (ledred); |
|
- | 197 | PORTC = 0x00; |
|
- | 198 | ||
Line 203... | Line 199... | ||
203 | PORTB = 0x00; |
199 | DDRD = (ledgreen|CH3_D|CH4_D|CH5_D); |
204 | 200 | PORTD = 0x00; |
|
205 | 201 | ||
206 | ch0 = 0; |
202 | ch0 = 0; |
207 | ch1 = 0; |
203 | ch1 = 0; |
208 | ch2 = 0; |
204 | ch2 = 0; |
Line 209... | Line 205... | ||
209 | ch3 = 0; |
205 | ch3 = 0; |
210 | ch4 = 0; |
206 | ch4 = 0; |
211 | ch5 = 0; |
207 | ch5 = 0; |
212 | 208 | ||
213 | //StartUART(); |
209 | //StartUART(); |
Line -... | Line 210... | ||
- | 210 | StartPPM(); |
|
- | 211 | //StartI2C(); |
|
- | 212 | StartPWM(); |
|
- | 213 | sei(); |
|
- | 214 | ||
Line 214... | Line 215... | ||
214 | StartPPM(); |
215 | |
215 | StartI2C(); |
216 | //rot > Violett > Blau > Türkis > Grün > Gelb > |
- | 217 | ||
216 | StartPWM(); |
218 | |
Line -... | Line 219... | ||
- | 219 | colorState = 0; |
|
- | 220 | ||
- | 221 | while (1) |
|
- | 222 | { |
|
- | 223 | ||
- | 224 | //printf("%d ",ppm_signal); |
|
- | 225 | ||
- | 226 | for (i=0; i<=255; i++) |
|
- | 227 | { |
|
- | 228 | switch(colorState) |
|
- | 229 | { |
|
- | 230 | case 0: |
|
- | 231 | ch0 = i; //fade in (ch0) red |
|
- | 232 | nextcolorState = 2; |
|
- | 233 | break; |
|
- | 234 | ||
- | 235 | case 2: |
|
- | 236 | ch1 = i; //fade in (ch1) blue to get purple (red + blue) |
|
- | 237 | nextcolorState = 4; |
|
- | 238 | break; |
|
- | 239 | ||
- | 240 | case 4: |
|
- | 241 | ch0 = 255 - i; //fade out (ch0) red to get pure blue |
|
- | 242 | nextcolorState = 6; |
|
- | 243 | break; |
|
- | 244 | ||
- | 245 | case 6: |
|
- | 246 | ch2 = i; //fade in (ch2) green to get cyan (blue + green) |
|
- | 247 | nextcolorState = 8; |
|
- | 248 | break; |
|
- | 249 | ||
- | 250 | case 8: |
|
- | 251 | ch1 = 255 - i; //fade out (ch1) blue to get pure green |
|
- | 252 | nextcolorState = 10; |
|
- | 253 | break; |
|
- | 254 | ||
- | 255 | case 10: |
|
- | 256 | ch0 = i; //fade in (ch0) red to get yellow (green + red) |
|
- | 257 | nextcolorState = 12; |
|
- | 258 | break; |
|
- | 259 | ||
- | 260 | case 12: |
|
- | 261 | ch2 = 255 - i; //fade out (ch2) green to get pure red |
|
- | 262 | nextcolorState = 0; |
|
- | 263 | break; |
|
- | 264 | } |
|
- | 265 | ||
- | 266 | ||
- | 267 | timer = SetDelay(1); |
|
Line 217... | Line -... | ||
217 | sei(); |
- | |
218 | - | ||
219 | 268 | while (!CheckDelay(timer)); |
|
Line 220... | Line 269... | ||
220 | while (1) |
269 | } |