Line 25... |
Line 25... |
25 |
#use fast_io(F) |
25 |
#use fast_io(F) |
26 |
#use fast_io(D) |
26 |
#use fast_io(D) |
27 |
#use fast_io(J) |
27 |
#use fast_io(J) |
28 |
|
28 |
|
29 |
#define T_REVERS 5 // 5*256 ms = 1,25 s; pred prepnutim rele (zastaveni motoru a vybiti kondenzatoru) |
29 |
#define T_REVERS 5 // 5*256 ms = 1,25 s; pred prepnutim rele (zastaveni motoru a vybiti kondenzatoru) |
30 |
#define T_START 1 // 256 ms; po prepnuti rele do sepnuti triaku |
30 |
#define T_START 2 // 2*256 ms = 0,5 s; po prepnuti rele do sepnuti triaku |
31 |
#define T_GO 117 // 117*256 ms = 30 s; max. beh rolety |
31 |
#define T_GO 117 // 117*256 ms = 30 s; max. beh rolety |
32 |
#define T_GO_ZALUZIE 6 // cca 1,5 s; beh zaluzie (pouze na preklopeni lamel) |
32 |
#define T_GO_ZALUZIE 6 // cca 1,5 s; beh zaluzie (pouze na preklopeni lamel) |
33 |
#define T_RECEIVE 10 // cca 2,6 s |
33 |
#define T_RECEIVE 10 // cca 2,6 s |
34 |
#define ZAKMIT 2000 // pocet pruchodu hlavni smyckou pred opetovnou detekci prepnuti vypinace |
34 |
#define ZAKMIT 2000 // pocet pruchodu hlavni smyckou pred opetovnou detekci prepnuti vypinace |
35 |
|
35 |
|
36 |
#define OR106Z PIN_A0 // t1 Zaluzie trucovna zapad |
36 |
#define OR106Z PIN_A0 // t1 Roleta trucovna zapad |
37 |
#define OR110N PIN_A1 // t2 Zaluzie koupelna dole sever |
37 |
#define OR110N PIN_A1 // t2 Zaluzie koupelna dole sever |
38 |
#define OR104V PIN_A2 // t3 Roleta lab vychod |
38 |
#define OR104V PIN_A2 // t3 Roleta lab vychod |
39 |
#define OR104J PIN_A3 // t4 Roleta lab jih |
39 |
#define OR104J PIN_A3 // t4 Roleta lab jih |
40 |
#define OR103V PIN_A4 // t5 Roleta loznice |
40 |
#define OR103V PIN_A4 // t5 Roleta loznice |
41 |
#define OR202J PIN_A5 // t6 Roleta Kaklik |
41 |
#define OR202J PIN_A5 // t6 Roleta Kaklik |
Line 126... |
Line 126... |
126 |
#define R104J 3 |
126 |
#define R104J 3 |
127 |
#define R207V 4 |
127 |
#define R207V 4 |
128 |
#define R202J 5 |
128 |
#define R202J 5 |
129 |
#define R204Z 6 |
129 |
#define R204Z 6 |
130 |
|
130 |
|
131 |
typedef enum {UP, DOWN, REVERS_UP, REVERS_DOWN, RUN_UP, RUN_DOWN} relay_state; |
131 |
typedef enum {UP, DOWN, REVERS_UP, REVERS_DOWN, RUN_UP, RUN_DOWN, RUN_UP_WAITING} relay_state; |
132 |
relay_state relay; // Stavy rele |
132 |
relay_state relay; // Stavy rele |
133 |
|
133 |
|
134 |
int8 timer_run; // Bezpecnostni casovac behu rolety |
134 |
int8 timer_run; // Bezpecnostni casovac behu rolety |
135 |
int8 timer_run_zaluzie; // Casovac zaluzie na preklopeni lamel |
135 |
int8 timer_run_zaluzie; // Casovac zaluzie na preklopeni lamel |
136 |
int8 timer_revers; // Prodleva na vybiti kondenzatoru pa zastaveni rolety pred prepnutim rele |
136 |
int8 timer_revers; // Prodleva na vybiti kondenzatoru pa zastaveni rolety pred prepnutim rele |
Line 143... |
Line 143... |
143 |
if(timer>0) timer--; |
143 |
if(timer>0) timer--; |
144 |
if(timer_run>0) timer_run--; |
144 |
if(timer_run>0) timer_run--; |
145 |
if(timer_revers>0) timer_revers--; |
145 |
if(timer_revers>0) timer_revers--; |
146 |
if(timer_start>0) timer_start--; |
146 |
if(timer_start>0) timer_start--; |
147 |
if(timer_run_zaluzie>0) timer_run_zaluzie--; |
147 |
if(timer_run_zaluzie>0) timer_run_zaluzie--; |
148 |
output_toggle(LED2); |
148 |
//!!!output_toggle(LED2); |
149 |
} |
149 |
} |
150 |
|
150 |
|
151 |
void stop_all() // Zastav vsechny rolety |
151 |
void stop_all() // Zastav vsechny rolety |
152 |
{ |
152 |
{ |
153 |
int8 n; |
153 |
int8 n; |
Line 166... |
Line 166... |
166 |
if (rol[R207V]==RUN) ON(OR207V); |
166 |
if (rol[R207V]==RUN) ON(OR207V); |
167 |
if (rol[R202J]==RUN) ON(OR202J); |
167 |
if (rol[R202J]==RUN) ON(OR202J); |
168 |
if (rol[R204Z]==RUN) ON(OR204Z); |
168 |
if (rol[R204Z]==RUN) ON(OR204Z); |
169 |
} |
169 |
} |
170 |
|
170 |
|
171 |
/* |
- |
|
172 |
void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
171 |
void run(int8 roleta) // Spust konkretni roletu |
173 |
{ |
172 |
{ |
174 |
switch (*status) |
173 |
switch (roleta) |
175 |
{ |
174 |
{ |
176 |
case STOP: |
175 |
case R103V: ON(OR103V); break; |
177 |
case GO_DOWN: |
176 |
case R110N: ON(OR110N); break; |
178 |
*status=REVERS_UP; |
177 |
case R104V: ON(OR104V); break; |
179 |
*timer=REVERS; |
- |
|
180 |
break; |
178 |
case R104J: ON(OR104J); break; |
181 |
case REVERS_UP: |
179 |
case R207V: ON(OR207V); break; |
182 |
case GO_UP: |
180 |
case R202J: ON(OR202J); break; |
183 |
*status=STOP; |
- |
|
184 |
*timer=0; |
- |
|
185 |
break; |
181 |
case R204Z: ON(OR204Z); break; |
186 |
} |
182 |
} |
187 |
} |
183 |
} |
188 |
|
184 |
|
189 |
void down(state *status, int8 *timer) // Zmena stavu rolety smer dolu |
185 |
void up(int8 roleta) // Pozadavek, aby roleta jela nahoru |
190 |
{ |
186 |
{ |
191 |
switch (*status) |
187 |
if (rol[roleta]==RUN) |
192 |
{ |
188 |
{ |
- |
|
189 |
rol[roleta]=STOP; // Roleta jela, tak zastav |
- |
|
190 |
} |
193 |
case STOP: |
191 |
else |
- |
|
192 |
{ |
- |
|
193 |
if ((relay==DOWN)||(relay==RUN_DOWN)) // Rele je prepnuto na druhou stranu! |
194 |
case GO_UP: |
194 |
{ |
195 |
*status=REVERS_DOWN; |
195 |
relay=REVERS_UP; // Reverzuj |
- |
|
196 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
- |
|
197 |
stop_all(); // Vsechno zastav |
- |
|
198 |
} |
196 |
*timer=REVERS; |
199 |
if (relay==RUN_UP) |
- |
|
200 |
{ |
- |
|
201 |
run(R207V); // Jede se spravnym smerem, tak jenom pust roletu |
- |
|
202 |
} |
- |
|
203 |
|
- |
|
204 |
rol[roleta]=RUN; // Roleta stala, tak ji pust |
- |
|
205 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
- |
|
206 |
} |
- |
|
207 |
} |
- |
|
208 |
|
- |
|
209 |
|
- |
|
210 |
void down(int8 roleta) // Pozadavek, aby roleta jela dolu |
- |
|
211 |
{ |
- |
|
212 |
if (rol[roleta]==RUN) |
- |
|
213 |
{ |
- |
|
214 |
rol[roleta]=STOP; // Roleta jela, tak zastav |
- |
|
215 |
} |
- |
|
216 |
else |
- |
|
217 |
{ |
- |
|
218 |
if ((relay==UP)||(relay==RUN_UP)||(relay==RUN_UP_WAITING)) // Rele je prepnuto na druhou stranu! |
197 |
break; |
219 |
{ |
198 |
case REVERS_DOWN: |
220 |
relay=REVERS_DOWN; // Reverzuj |
- |
|
221 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
- |
|
222 |
stop_all(); // Vsechno zastav |
199 |
case GO_DOWN: |
223 |
} |
200 |
*status=STOP; |
224 |
if (relay==RUN_DOWN) |
201 |
*timer=0; |
225 |
{ |
- |
|
226 |
run(R207V); // Jede se spravnym smerem, tak jenom pust roletu |
202 |
break; |
227 |
} |
- |
|
228 |
|
- |
|
229 |
rol[roleta]=RUN; // Roleta stala, tak ji pust |
- |
|
230 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
203 |
} |
231 |
} |
204 |
} |
232 |
} |
205 |
|
233 |
|
206 |
#define run(x) { \ |
- |
|
207 |
switch(r##x) \ |
- |
|
208 |
{ \ |
- |
|
209 |
case STOP: \ |
- |
|
210 |
OFF(OR##x##U); \ |
- |
|
211 |
OFF(OR##x##D); \ |
- |
|
212 |
break; \ |
- |
|
213 |
case GO_UP: \ |
- |
|
214 |
OFF(OR##x##D); \ |
- |
|
215 |
ON(OR##x##U); \ |
- |
|
216 |
if(tr##x==0) {r##x=STOP;} \ |
- |
|
217 |
break; \ |
- |
|
218 |
case GO_DOWN: \ |
- |
|
219 |
OFF(OR##x##U); \ |
- |
|
220 |
ON(OR##x##D); \ |
- |
|
221 |
if(tr##x==0) {r##x=STOP;} \ |
- |
|
222 |
break; \ |
- |
|
223 |
case REVERS_UP: \ |
- |
|
224 |
OFF(OR##x##U); \ |
- |
|
225 |
OFF(OR##x##D); \ |
- |
|
226 |
if(tr##x==0) {r##x=GO_UP; tr##x=GO;} \ |
- |
|
227 |
break; \ |
- |
|
228 |
case REVERS_DOWN: \ |
- |
|
229 |
OFF(OR##x##U); \ |
- |
|
230 |
OFF(OR##x##D); \ |
- |
|
231 |
if(tr##x==0) {r##x=GO_DOWN; tr##x=GO;} \ |
- |
|
232 |
break; \ |
- |
|
233 |
} \ |
- |
|
234 |
} |
- |
|
235 |
*/ |
- |
|
236 |
|
234 |
|
237 |
void main() |
235 |
void main() |
238 |
{ |
236 |
{ |
239 |
char buf[10]; // Buffer pro prijem prikazu |
237 |
char buf[10]; // Buffer pro prijem prikazu |
240 |
unsigned int16 zakmity=0; // Osetreni zakmitu vypinacu |
238 |
unsigned int16 zakmity=0; // Osetreni zakmitu vypinacu |
Line 263... |
Line 261... |
263 |
output_b(0xFF); |
261 |
output_b(0xFF); |
264 |
output_f(0xFF); |
262 |
output_f(0xFF); |
265 |
output_e(0xFF); |
263 |
output_e(0xFF); |
266 |
stop_all(); |
264 |
stop_all(); |
267 |
|
265 |
|
268 |
timer_run=0; // Zastav vsechny casovace |
- |
|
269 |
timer=0; |
- |
|
270 |
timer_revers=0; |
- |
|
271 |
timer_start=0; |
- |
|
272 |
timer_run_zaluzie=0; |
- |
|
273 |
zakmity=0; |
- |
|
274 |
|
- |
|
275 |
relay=RUN_UP; // Rele je na zacatku vypnuto |
266 |
relay=RUN_UP_WAITING; // Rele je na zacatku vypnuto |
276 |
|
267 |
|
277 |
{ |
268 |
{ |
278 |
int n; |
269 |
int n; |
279 |
|
270 |
|
280 |
for(n=0;n<10;n++) |
271 |
for(n=0;n<10;n++) |
Line 299... |
Line 290... |
299 |
r202NU=IR202NU; |
290 |
r202NU=IR202NU; |
300 |
s205A=IS205A; |
291 |
s205A=IS205A; |
301 |
s204AJ=IS204AJ; |
292 |
s204AJ=IS204AJ; |
302 |
r204ZD=IR204ZD; |
293 |
r204ZD=IR204ZD; |
303 |
r204ZU=IR204ZU; |
294 |
r204ZU=IR204ZU; |
304 |
|
295 |
|
305 |
CREN=0; CREN=1; // Reinitialise USART |
296 |
timer_run=0; // Zastav vsechny casovace |
- |
|
297 |
timer=0; |
- |
|
298 |
timer_revers=0; |
- |
|
299 |
timer_start=0; |
- |
|
300 |
timer_run_zaluzie=0; |
- |
|
301 |
zakmity=0; |
306 |
|
302 |
|
307 |
enable_interrupts(INT_TIMER0); |
303 |
enable_interrupts(INT_TIMER0); |
308 |
enable_interrupts(GLOBAL); |
304 |
enable_interrupts(GLOBAL); |
309 |
|
305 |
|
- |
|
306 |
CREN=0; CREN=1; // Reinitialise USART |
- |
|
307 |
|
310 |
while(TRUE) |
308 |
while(TRUE) |
311 |
{ |
309 |
{ |
312 |
restart_wdt(); |
310 |
restart_wdt(); |
313 |
|
311 |
|
314 |
if(kbhit()) // Chce po nas nekdo neco? |
312 |
if(kbhit()) // Chce po nas nekdo neco? |
Line 431... |
Line 429... |
431 |
} |
429 |
} |
432 |
if (relay==RUN_UP) |
430 |
if (relay==RUN_UP) |
433 |
{ |
431 |
{ |
434 |
ON(OR207V); // Jede se spravnym smerem, tak jenom pust roletu |
432 |
ON(OR207V); // Jede se spravnym smerem, tak jenom pust roletu |
435 |
} |
433 |
} |
436 |
rol[R104V]=RUN; // Poznamenej, ze se jede, a natahni bezpecnostni casovac |
434 |
rol[R207V]=RUN; // Poznamenej, ze se jede, a natahni bezpecnostni casovac |
437 |
timer_run=T_GO; |
435 |
timer_run=T_GO; |
438 |
} |
436 |
} |
439 |
zakmity=ZAKMIT; |
437 |
zakmity=ZAKMIT; |
440 |
} |
438 |
} |
441 |
if(r207VD!=IR207VD) |
439 |
if(r207VD!=IR207VD) |
Line 447... |
Line 445... |
447 |
rol[R207V]=STOP; |
445 |
rol[R207V]=STOP; |
448 |
OFF(OR207V); |
446 |
OFF(OR207V); |
449 |
} |
447 |
} |
450 |
else |
448 |
else |
451 |
{ |
449 |
{ |
452 |
if ((relay==UP)||(relay==RUN_UP)) |
450 |
if ((relay==UP)||(relay==RUN_UP)||(relay==RUN_UP_WAITING)) |
453 |
{ |
451 |
{ |
454 |
relay=REVERS_DOWN; |
452 |
relay=REVERS_DOWN; |
455 |
timer_revers=T_REVERS; |
453 |
timer_revers=T_REVERS; |
456 |
stop_all(); |
454 |
stop_all(); |
457 |
} |
455 |
} |
458 |
if (relay==RUN_DOWN) |
456 |
if (relay==RUN_DOWN) |
459 |
{ |
457 |
{ |
460 |
ON(OR207V); |
458 |
ON(OR207V); |
461 |
} |
459 |
} |
462 |
rol[R104V]=RUN; |
460 |
rol[R207V]=RUN; |
463 |
timer_run=T_GO; |
461 |
timer_run=T_GO; |
464 |
} |
462 |
} |
465 |
zakmity=ZAKMIT; |
463 |
zakmity=ZAKMIT; |
466 |
} |
464 |
} |
467 |
|
465 |
|
- |
|
466 |
if(r207VU!=IR207VU) {r207VU=IR207VU; up(R207V); zakmity=ZAKMIT;} |
- |
|
467 |
if(r207VD!=IR207VD) {r207VD=IR207VD; down(R207V); zakmity=ZAKMIT;} |
468 |
//!!! if(r202NU!=IR202NU) {r202NU=IR202NU; up(&r202J,&tr202J); zakmity=ZAKMIT;} |
468 |
if(r202NU!=IR202NU) {r202NU=IR202NU; up(R202J); zakmity=ZAKMIT;} |
469 |
//!!! if(r202ND!=IR202ND) {r202ND=IR202ND; down(&r202J,&tr202J); zakmity=ZAKMIT;} |
469 |
if(r202ND!=IR202ND) {r202ND=IR202ND; down(R202J); zakmity=ZAKMIT;} |
470 |
//!!! if(r204ZU!=IR204ZU) {r204ZU=IR204ZU; up(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
470 |
if(r204ZU!=IR204ZU) {r204ZU=IR204ZU; up(R204Z); zakmity=ZAKMIT;} |
471 |
//!!! if(r204ZD!=IR204ZD) {r204ZD=IR204ZD; down(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
471 |
if(r204ZD!=IR204ZD) {r204ZD=IR204ZD; down(R204Z); zakmity=ZAKMIT;} |
472 |
} |
472 |
} |
473 |
else zakmity--; |
473 |
else zakmity--; |
474 |
} |
474 |
|
- |
|
475 |
switch (relay) |
- |
|
476 |
{ |
- |
|
477 |
case UP: |
- |
|
478 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
- |
|
479 |
{ |
- |
|
480 |
relay=RUN_UP; // Zmen stav na "jede se" |
- |
|
481 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
- |
|
482 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
- |
|
483 |
} |
- |
|
484 |
break; |
475 |
|
485 |
|
476 |
switch (relay) |
- |
|
477 |
{ |
- |
|
478 |
case UP: |
- |
|
479 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
- |
|
480 |
{ |
- |
|
481 |
relay=RUN_UP; // Zmen stav na "jede se" |
- |
|
482 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
- |
|
483 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
- |
|
484 |
} |
- |
|
485 |
break; |
- |
|
486 |
|
- |
|
487 |
case DOWN: |
486 |
case DOWN: |
488 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
487 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
489 |
{ |
488 |
{ |
490 |
relay=RUN_DOWN; // Zmen stav na "jede se" |
489 |
relay=RUN_DOWN; // Zmen stav na "jede se" |
491 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
490 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
492 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
491 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
493 |
} |
492 |
} |
494 |
break; |
493 |
break; |
495 |
|
494 |
|
496 |
case RUN_UP: |
495 |
case RUN_UP: |
497 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
496 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
498 |
{ |
497 |
{ |
- |
|
498 |
timer=RUN_UP_WAITING; |
499 |
stop_all(); // Vsechno zastav |
499 |
stop_all(); // Vsechno zastav |
500 |
} |
500 |
} |
501 |
break; |
501 |
break; |
502 |
|
502 |
|
503 |
case RUN_DOWN: |
503 |
case RUN_DOWN: |
504 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
504 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
505 |
{ |
505 |
{ |
506 |
relay=REVERS_UP; // Vsechno zastav a reverzuj pro prepnuti rele do klidove polohy bez energizace civky |
506 |
relay=REVERS_UP; // Vsechno zastav a reverzuj pro prepnuti rele do klidove polohy bez energizace civky |
507 |
stop_all(); |
507 |
stop_all(); |
508 |
timer_revers=T_REVERS; |
508 |
timer_revers=T_REVERS; |
509 |
} |
509 |
} |
510 |
break; |
510 |
break; |
511 |
|
511 |
|
512 |
case REVERS_UP: |
512 |
case REVERS_UP: |
513 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
513 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
514 |
{ |
514 |
{ |
515 |
relay=UP; // Prepni rele |
515 |
relay=UP; // Prepni rele |
516 |
OFF(RE); |
516 |
OFF(RE); |
517 |
timer_start=T_START; // Pockej na prepnuti rele |
517 |
timer_start=T_START; // Pockej na prepnuti rele |
518 |
} |
518 |
} |
519 |
break; |
519 |
break; |
520 |
|
520 |
|
521 |
case REVERS_DOWN: |
521 |
case REVERS_DOWN: |
522 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
522 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
523 |
{ |
523 |
{ |
524 |
relay=DOWN; // Prepni rele |
524 |
relay=DOWN; // Prepni rele |
525 |
ON(RE); |
525 |
ON(RE); |
526 |
timer_start=T_START; // Pockej na prepnuti rele |
526 |
timer_start=T_START; // Pockej na prepnuti rele |
527 |
} |
527 |
} |
528 |
break; |
528 |
break; |
- |
|
529 |
} |
529 |
} |
530 |
} |
530 |
} |
531 |
} |