Rev 1746 | Rev 1747 | ||
---|---|---|---|
Line 1... | Line 1... | ||
1 | #include "main.h" |
1 | #include "main.h" |
2 | |
2 | |
3 | #case |
3 | #case |
4 | |
4 | |
- | 5 | #define REVERS 2 // 2*256 ms = 0,5 s |
|
- | 6 | #define GO 117 // 117*256 ms = 30 s |
|
- | 7 | #define GO_ZALUZIE 5 // 5*256 ms = 1,25 s |
|
- | 8 | |
|
5 | #define S105A PIN_A0 |
9 | #define S105A PIN_A0 |
6 | #define R105AU PIN_A1 |
10 | #define R110AU PIN_A1 |
7 | #define R105AD PIN_A2 |
11 | #define R110AD PIN_A2 |
8 | #define S104A PIN_A3 |
12 | #define S104A PIN_A3 |
9 | #define R104AU PIN_A4 |
13 | #define R104AU PIN_A4 |
10 | #define R104AD PIN_A5 |
14 | #define R104AD PIN_A5 |
11 | #define R104BU PIN_A6 |
15 | #define R104BU PIN_A6 |
12 | #define R104BD PIN_A7 |
16 | #define R104BD PIN_A7 |
Line 79... | Line 83... | ||
79 | #define PIN_J5 31813 |
83 | #define PIN_J5 31813 |
80 | #define PIN_J6 31814 |
84 | #define PIN_J6 31814 |
81 | #define PIN_J7 31815 |
85 | #define PIN_J7 31815 |
82 | */ |
86 | */ |
83 | |
87 | |
- | 88 | #bit CREN = 0xFAB.4 // USART enable register |
|
- | 89 | |
|
84 | #define LED1 PIN_J7 |
90 | #define LED1 PIN_J7 |
85 | #define LED2 PIN_J6 |
91 | #define LED2 PIN_J6 |
86 | |
92 | |
87 | #define ON(port) output_low(port); |
93 | #define ON(port) output_low(port); |
88 | #define OFF(port) output_high(port); |
94 | #define OFF(port) output_high(port); |
89 | |
95 | |
90 | typedef enum {UP, DOWN, NOTHING} request; |
96 | typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
- | 97 | |
|
- | 98 | state r103A, r110A, r104A, r104B; // Stavy rolet |
|
- | 99 | int8 tr103A, tr110A, tr104A, tr104B; // Casovace rolet |
|
- | 100 | |
|
- | 101 | #int_TIMER0 |
|
- | 102 | void TIMER0_isr(void) |
|
- | 103 | { |
|
- | 104 | if(tr103A>0) tr103A--; |
|
- | 105 | if(tr110A>0) tr110A--; |
|
- | 106 | if(tr104A>0) tr104A--; |
|
- | 107 | if(tr104B>0) tr104B--; |
|
- | 108 | output_toggle(LED2); |
|
- | 109 | } |
|
- | 110 | |
|
- | 111 | void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
|
- | 112 | { |
|
- | 113 | switch (*status) |
|
- | 114 | { |
|
- | 115 | case STOP: |
|
- | 116 | case GO_DOWN: |
|
- | 117 | *status=REVERS_UP; |
|
- | 118 | *timer=REVERS; |
|
- | 119 | break; |
|
- | 120 | case REVERS_UP: |
|
- | 121 | case GO_UP: |
|
- | 122 | *status=STOP; |
|
- | 123 | *timer=0; |
|
- | 124 | break; |
|
- | 125 | } |
|
- | 126 | } |
|
- | 127 | |
|
- | 128 | void down(state *status, int8 *timer) // Zmena stavu rolety smer dolu |
|
- | 129 | { |
|
- | 130 | switch (*status) |
|
- | 131 | { |
|
- | 132 | case STOP: |
|
- | 133 | case GO_UP: |
|
- | 134 | *status=REVERS_DOWN; |
|
- | 135 | *timer=REVERS; |
|
- | 136 | break; |
|
- | 137 | case REVERS_DOWN: |
|
- | 138 | case GO_DOWN: |
|
- | 139 | *status=STOP; |
|
- | 140 | *timer=0; |
|
- | 141 | break; |
|
- | 142 | } |
|
- | 143 | } |
|
- | 144 | |
|
- | 145 | #define run(x) { \ |
|
- | 146 | switch(r##x) \ |
|
- | 147 | { \ |
|
- | 148 | case STOP: \ |
|
- | 149 | OFF(R##x##U); \ |
|
- | 150 | OFF(R##x##D); \ |
|
- | 151 | break; \ |
|
- | 152 | case GO_UP: \ |
|
- | 153 | ON(R##x##U); \ |
|
- | 154 | OFF(R##x##D); \ |
|
- | 155 | if(tr##x==0) {r##x=STOP;} \ |
|
- | 156 | break; \ |
|
- | 157 | case GO_DOWN: \ |
|
- | 158 | OFF(R##x##U); \ |
|
- | 159 | ON(R##x##D); \ |
|
- | 160 | if(tr##x==0) {r##x=STOP;} \ |
|
- | 161 | break; \ |
|
- | 162 | case REVERS_UP: \ |
|
- | 163 | OFF(R##x##U); \ |
|
- | 164 | OFF(R##x##D); \ |
|
- | 165 | if(tr##x==0) {r##x=GO_UP; tr##x=GO;} \ |
|
- | 166 | break; \ |
|
- | 167 | case REVERS_DOWN: \ |
|
- | 168 | OFF(R##x##U); \ |
|
- | 169 | OFF(R##x##D); \ |
|
- | 170 | if(tr##x==0) {r##x=GO_DOWN; tr##x=GO;} \ |
|
- | 171 | break; \ |
|
- | 172 | } \ |
|
- | 173 | } |
|
91 | |
174 | |
92 | void main() |
175 | void main() |
93 | { |
176 | { |
94 | char c; |
177 | char c; |
95 | |
178 | |
Line 98... | Line 181... | ||
98 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
181 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
99 | setup_adc(ADC_CLOCK_DIV_2); |
182 | setup_adc(ADC_CLOCK_DIV_2); |
100 | setup_psp(PSP_DISABLED); |
183 | setup_psp(PSP_DISABLED); |
101 | setup_spi(SPI_SS_DISABLED); |
184 | setup_spi(SPI_SS_DISABLED); |
102 | setup_wdt(WDT_ON); |
185 | setup_wdt(WDT_ON); |
103 | setup_timer_0(RTCC_INTERNAL); |
186 | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
104 | setup_timer_1(T1_DISABLED); |
187 | setup_timer_1(T1_DISABLED); |
105 | setup_timer_2(T2_DISABLED,0,1); |
188 | setup_timer_2(T2_DISABLED,0,1); |
106 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
189 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
107 | setup_ccp1(CCP_OFF); |
190 | setup_ccp1(CCP_OFF); |
108 | setup_comparator(NC_NC_NC_NC); |
191 | setup_comparator(NC_NC_NC_NC); |
109 | setup_vref(FALSE); |
192 | setup_vref(FALSE); |
110 | |
193 | |
111 | OFF(S105A); |
194 | OFF(S105A); // Vsechno zhasni a zastav |
112 | OFF(R105AU); |
195 | OFF(R110AU); |
113 | OFF(R105AD); |
196 | OFF(R110AD); |
114 | OFF(S104A); |
197 | OFF(S104A); |
115 | OFF(R104AU); |
198 | OFF(R104AU); |
116 | OFF(R104AD); |
199 | OFF(R104AD); |
117 | OFF(R104BU); |
200 | OFF(R104BU); |
118 | OFF(R104BD); |
201 | OFF(R104BD); |
Line 127... | Line 210... | ||
127 | OFF(S102A); |
210 | OFF(S102A); |
128 | OFF(S110C); |
211 | OFF(S110C); |
129 | OFF(S108A); |
212 | OFF(S108A); |
130 | OFF(S201A); |
213 | OFF(S201A); |
131 | OFF(S110B); |
214 | OFF(S110B); |
- | 215 | |
|
- | 216 | r103A=STOP; // Rolety jsou zastaveny |
|
- | 217 | r110A=STOP; |
|
- | 218 | r104A=STOP; |
|
- | 219 | r104B=STOP; |
|
- | 220 | |
|
- | 221 | enable_interrupts(INT_TIMER0); |
|
- | 222 | enable_interrupts(GLOBAL); |
|
132 | } |
223 | } |
133 | |
224 | |
- | 225 | CREN=0; CREN=1; // Reinitialise USART |
|
- | 226 | |
|
134 | while(TRUE) |
227 | while(TRUE) |
135 | { |
228 | { |
136 | if(kbhit()) |
229 | if(kbhit()) |
137 | { |
230 | { |
138 | c=getc(); |
231 | c=getc(); |
139 | if(c=='S') |
232 | if(c=='S') |
140 | { |
233 | { |
141 | getc(); |
- | |
142 | switch(getc()) |
234 | if(getc()=='1') |
143 | { |
235 | { |
- | 236 | switch(getc()) |
|
- | 237 | { |
|
144 | case '1': |
238 | case '1': |
145 | output_toggle(S101A); |
239 | output_toggle(S101A); |
146 | break; |
240 | break; |
147 | case '2': |
241 | case '2': |
148 | output_toggle(S102A); |
242 | output_toggle(S102A); |
149 | break; |
243 | break; |
150 | case '3': |
244 | case '3': |
151 | output_toggle(S103A); |
245 | output_toggle(S103A); |
152 | break; |
246 | break; |
153 | case '4': |
247 | case '4': |
154 | output_toggle(S104A); |
248 | output_toggle(S104A); |
155 | break; |
249 | break; |
156 | case '5': |
250 | case '5': |
157 | c=getc(); |
251 | c=getc(); |
158 | if(c=='A') {output_toggle(S105A);} |
252 | if(c=='A') {output_toggle(S105A);} |
159 | if(c=='D') {output_toggle(S105D);} |
253 | if(c=='D') {output_toggle(S105D);} |
160 | break; |
254 | break; |
161 | case '6': |
255 | case '6': |
162 | output_toggle(S106A); |
256 | output_toggle(S106A); |
163 | break; |
257 | break; |
164 | case '7': |
258 | case '7': |
165 | output_toggle(S107A); |
259 | output_toggle(S107A); |
166 | break; |
260 | break; |
167 | case '8': |
261 | case '8': |
168 | output_toggle(S108A); |
262 | output_toggle(S108A); |
169 | break; |
263 | break; |
170 | case '9': |
264 | case '9': |
171 | output_toggle(S109A); |
265 | output_toggle(S109A); |
172 | break; |
266 | break; |
173 | case 'a': |
267 | case 'a': |
174 | output_toggle(S110B); |
268 | output_toggle(S110B); |
175 | output_toggle(S110C); |
269 | output_toggle(S110C); |
176 | break; |
270 | break; |
- | 271 | } |
|
177 | } |
272 | } |
178 | } |
273 | } |
179 | |
274 | |
180 | if(c=='R') |
275 | if(c=='R') |
181 | { |
276 | { |
182 | getc(); |
- | |
183 | switch(getc()) |
277 | if(getc()=='1') |
184 | { |
278 | { |
185 | case '3': |
279 | switch(getc()) |
186 | getc(); |
280 | { |
187 | c=getc(); |
281 | case '3': |
188 | if((c=='U')) {}; |
282 | getc(); // A |
- | 283 | if((getc()=='U')) {up(&r103A,&tr103A);} else {down(&r103A,&tr103A);} |
|
189 | break; |
284 | break; |
190 | case '4': |
285 | case '4': |
191 | c=getc(); |
286 | c=getc(); |
192 | if(c=='A') {}; |
287 | if(c=='A') if((getc()=='U')) {up(&r104A,&tr104A);} else {down(&r104A,&tr104A);} |
193 | if(c=='B') {}; |
288 | if(c=='B') if((getc()=='U')) {up(&r104B,&tr104B);} else {down(&r104B,&tr104B);} |
194 | break; |
289 | break; |
195 | case '5': |
290 | case 'a': |
196 | getc(); |
291 | getc(); // A |
- | 292 | if((getc()=='U')) {up(&r110A,&tr110A);} else {down(&r110A,&tr110A);} |
|
197 | getc(); |
293 | break; |
198 | break; |
294 | } |
199 | } |
295 | } |
200 | } |
296 | } |
- | 297 | |
|
201 | output_toggle(LED1); |
298 | output_toggle(LED1); // Prijmuli jsme cely prikaz |
202 | } |
299 | } |
203 | else |
300 | else |
204 | { |
301 | { |
- | 302 | run(103A); |
|
- | 303 | run(104A); |
|
- | 304 | run(104B); |
|
- | 305 | |
|
- | 306 | switch(r110A) |
|
- | 307 | { |
|
- | 308 | case STOP: |
|
- | 309 | OFF(R110AU); |
|
- | 310 | OFF(R110AD); |
|
- | 311 | break; |
|
- | 312 | case GO_UP: |
|
- | 313 | ON(R110AU); |
|
- | 314 | OFF(R110AD); |
|
- | 315 | if(tr110A==0) {r110A=STOP;} |
|
- | 316 | break; |
|
- | 317 | case GO_DOWN: |
|
- | 318 | OFF(R110AU); |
|
- | 319 | ON(R110AD); |
|
- | 320 | if(tr110A==0) {r110A=STOP;} |
|
- | 321 | break; |
|
- | 322 | case REVERS_UP: |
|
- | 323 | OFF(R110AU); |
|
- | 324 | OFF(R110AD); |
|
- | 325 | if(tr110A==0) {r110A=GO_UP; tr110A=GO_ZALUZIE;} |
|
- | 326 | break; |
|
- | 327 | case REVERS_DOWN: |
|
- | 328 | OFF(R110AU); |
|
- | 329 | OFF(R110AD); |
|
- | 330 | if(tr110A==0) {r110A=GO_DOWN; tr110A=GO_ZALUZIE;} |
|
- | 331 | break; |
|
- | 332 | } |
|
- | 333 | /* |
|
- | 334 | switch(r110A) |
|
- | 335 | { |
|
- | 336 | case GO_UP: |
|
- | 337 | printf("U"); |
|
- | 338 | break; |
|
- | 339 | case GO_DOWN: |
|
- | 340 | printf("D"); |
|
- | 341 | break; |
|
- | 342 | case REVERS_UP: |
|
- | 343 | printf("R"); |
|
- | 344 | break; |
|
- | 345 | case REVERS_DOWN: |
|
- | 346 | printf("E"); |
|
- | 347 | break; |
|
- | 348 | case STOP: |
|
- | 349 | printf("S"); |
|
- | 350 | break; |
|
- | 351 | } |
|
- | 352 | */ |
|
205 | restart_wdt(); |
353 | restart_wdt(); |
206 | } |
354 | } |
207 | } |
355 | } |
208 | } |
356 | } |