2080 |
kakl |
1 |
/* |
|
|
2 |
Ovladani domu rozvadec 2. n.p. |
|
|
3 |
|
|
|
4 |
Syntaxe prikazu: |
|
|
5 |
|
|
|
6 |
<Roleta/Svetlo><#patro><#mistnost><Nord/Jih/Vychod/Zapad/A/B><Up/Down> |
|
|
7 |
R2aNU - roleta, 2. n.p., mistnost 10, sever, nahoru |
|
|
8 |
S12A - svetlo, 1. n.p., mistnost 2, prostredni |
|
|
9 |
|
2081 |
kakl |
10 |
Rozmisteni desek: |
|
|
11 |
|
2494 |
kakl |
12 |
[IN D] |
|
|
13 |
[OUT E] |
|
|
14 |
[IN H] [IN J] |
|
|
15 |
[OUT B] |
|
|
16 |
[CPU] |
2081 |
kakl |
17 |
|
2494 |
kakl |
18 |
[OUT G] [CAN] [OUT A] [OUT F] |
2081 |
kakl |
19 |
|
2080 |
kakl |
20 |
*/ |
1746 |
kakl |
21 |
#include "main.h" |
|
|
22 |
|
|
|
23 |
#case |
2085 |
kakl |
24 |
#use fast_io(A) // Aby se neztracely znaky pri cteni prikazu |
|
|
25 |
#use fast_io(B) |
|
|
26 |
#use fast_io(E) |
|
|
27 |
#use fast_io(F) |
|
|
28 |
#use fast_io(D) |
|
|
29 |
#use fast_io(J) |
2494 |
kakl |
30 |
#use fast_io(H) |
|
|
31 |
#use fast_io(G) |
1746 |
kakl |
32 |
|
2497 |
kakl |
33 |
#define T_REVERS 2 // 2*256 ms = 0,5 s; pred prepnutim rele (zastaveni motoru a vybiti kondenzatoru) |
|
|
34 |
#define T_START 1 // 1*256 ms = 0,3 s; po prepnuti rele do sepnuti triaku |
|
|
35 |
#define T_GO 117 // 117*256 ms = 30 s; max. beh rolety |
|
|
36 |
#define T_GO_ZALUZIE 2500/256 // cca 2 s; beh zaluzie (pouze na preklopeni lamel) |
|
|
37 |
#define T_RECEIVE 10 // cca 2,6 s |
|
|
38 |
#define TIMEOUT_SPAJZ 255 // Timeout svetlo spajz cca minuta |
|
|
39 |
#define ZAKMIT 2000 // pocet pruchodu hlavni smyckou pred opetovnou detekci prepnuti vypinace |
1747 |
kakl |
40 |
|
2497 |
kakl |
41 |
//!!! STUDENAK na triaku spolecny vyvod !!! #define O PIN_A0 // t1 |
2231 |
kakl |
42 |
#define OR110N PIN_A1 // t2 Zaluzie koupelna dole sever |
|
|
43 |
#define OR104V PIN_A2 // t3 Roleta lab vychod |
|
|
44 |
#define OR104J PIN_A3 // t4 Roleta lab jih |
|
|
45 |
#define OR103V PIN_A4 // t5 Roleta loznice |
|
|
46 |
#define OR202J PIN_A5 // t6 Roleta Kaklik |
|
|
47 |
#define OR204Z PIN_A6 // t7 Roleta radiomistnost |
|
|
48 |
#define OR207V PIN_A7 // t8 Roleta klubovna |
1746 |
kakl |
49 |
|
2231 |
kakl |
50 |
#define OR208V PIN_F0 // t1 Roleta Zizala vychod |
|
|
51 |
#define OR208J PIN_F1 // t2 Roleta Zizala jih |
2497 |
kakl |
52 |
//??? #define OR107 PIN_F2 // t3 Roleta satna |
|
|
53 |
#define OR106J PIN_F3 // t4 Roleta trucovna jih |
2231 |
kakl |
54 |
#define OR201Z PIN_F4 // t5 Roleta chodba nahore |
|
|
55 |
#define OR205N PIN_F5 // t6 Roleta puda |
2499 |
kakl |
56 |
#define OR105J PIN_F6 // t7 Roleta kuchyn |
2497 |
kakl |
57 |
#define OR106Z PIN_F7 // t8 Roleta trucovna zapad |
2231 |
kakl |
58 |
|
2080 |
kakl |
59 |
#define OS103J PIN_B0 // t1 Svetla loznice |
|
|
60 |
#define OS105Z PIN_B1 // t2 Svetlo kuchyn nad lavici |
2499 |
kakl |
61 |
#define OS110V PIN_B2 // t3 Svetlo koupelna dole zachod a zrcadlo |
2080 |
kakl |
62 |
#define OS106A PIN_B3 // t4 Svetlo trucovna stred |
|
|
63 |
#define OS107A PIN_B4 // t5 Svetlo satna |
|
|
64 |
#define OS109A PIN_B5 // t6 Svetlo technologicka mistnost |
2084 |
kakl |
65 |
#define OS205A PIN_B6 // t7 Svetlo puda |
|
|
66 |
#define OS204A PIN_B7 // t8 Svetlo radiomistnost |
1746 |
kakl |
67 |
|
|
|
68 |
//#define OS105C PIN_C2 |
|
|
69 |
//#define PIN_C3 31763 |
|
|
70 |
//#define PIN_C4 31764 |
|
|
71 |
//#define PIN_C5 31765 |
|
|
72 |
//#define PIN_C6 31766 //TX |
|
|
73 |
//#define PIN_C7 31767 //RX |
|
|
74 |
|
2085 |
kakl |
75 |
#define OS102A PIN_E0 // t1 Svetlo chodba |
|
|
76 |
#define OS105A PIN_E1 // t2 Svetlo kuchyne stred |
|
|
77 |
#define OS207A PIN_E2 // t3 Svetlo klubovna |
|
|
78 |
#define OS104A PIN_E3 // t4 Svetlo laborator |
|
|
79 |
#define OS202A PIN_E4 // t5 Svetlo Kaklik stred |
|
|
80 |
#define OS209A PIN_E5 // t6 Svetlo Zizala koupelna |
|
|
81 |
#define OS203A PIN_E6 // t7 Svetlo Kaklik koupelna |
2231 |
kakl |
82 |
#define RE PIN_E7 // t8 Rele pro rizeni smeru rolet |
2085 |
kakl |
83 |
|
2494 |
kakl |
84 |
//#define O.... PIN_G0 // t8 |
2499 |
kakl |
85 |
#define OS110J PIN_G1 // t7 Svetlo sprcha v dolni koupelne |
2497 |
kakl |
86 |
#define OS108A PIN_G2 // t6 Svetlo spajz |
2494 |
kakl |
87 |
#define OS208A PIN_G3 // t5 Svetlo Zizala stred |
|
|
88 |
#define OS100A PIN_G4 // t4 Svetlo prujezd venku |
|
|
89 |
|
|
|
90 |
//#define I.... input(PIN_D0) // A |
2084 |
kakl |
91 |
#define IS201AZ input(PIN_D1) // B Vypinac chodba 2.n.p. zapad u Kaklika |
|
|
92 |
#define IS207AJ input(PIN_D2) // C Vypinac klubovna |
|
|
93 |
#define IR207VD input(PIN_D3) // D Vypinac roleta klubovna dolu |
|
|
94 |
#define IR207VU input(PIN_D4) // E Vypinac roleta klubovna nahoru |
|
|
95 |
#define IS201AV input(PIN_D5) // F Vypinac chodba 2.n.p. vychod |
|
|
96 |
#define IS209AJ input(PIN_D6) // G Vypinac koupelna Zizala |
|
|
97 |
#define IS203AJ input(PIN_D7) // H Vypinac koupelna Kaklik |
|
|
98 |
|
|
|
99 |
#define IS202AN input(PIN_J0) // A Vypinac svetlo Kaklik stred u dveri na chodbu |
|
|
100 |
#define IR202ND input(PIN_J1) // B Vypinac roleta Kaklik dolu u dveri |
|
|
101 |
#define IR202NU input(PIN_J2) // C Vypinac roleta Kaklik nahoru u dveri |
|
|
102 |
#define IS205A input(PIN_J3) // D Vypinac svetlo puda |
|
|
103 |
#define IS204AJ input(PIN_J4) // E Vypinac svetlo radiomistnost u dveri na chodbu |
|
|
104 |
#define IR204ZD input(PIN_J5) // F Vypinac roleta radiomistnost dolu |
|
|
105 |
#define IR204ZU input(PIN_J6) // G Vypinac roleta radiomistnost nahoru |
2497 |
kakl |
106 |
#define IS108A input(PIN_J7) // H Mikrospinac spajz |
2084 |
kakl |
107 |
|
2494 |
kakl |
108 |
#define IS208AN input(PIN_H0) // A Vypinac svetlo stred Zizala u dveri na chodbu //POZOR! Jsou prohozeny rolety J a V a smery U a D |
|
|
109 |
#define IR208JD input(PIN_H1) // B Vypinac roleta vychod Zizala nahoru u dveri |
|
|
110 |
#define IR208JU input(PIN_H2) // C Vypinac roleta vychod Zizala dolu u dveri |
|
|
111 |
#define IR208VD input(PIN_H3) // D Vypinac roleta jih Zizala nahoru u dveri |
|
|
112 |
#define IR208VU input(PIN_H4) // E Vypinac roleta jih Zizala dolu u dveri |
|
|
113 |
//#define I.... input(PIN_H5) // F |
|
|
114 |
//#define I.... input(PIN_H6) // G |
|
|
115 |
#define Ispec input(PIN_H7) // H specialni vypinac u rozvadece 2.n.p. |
|
|
116 |
|
|
|
117 |
|
2080 |
kakl |
118 |
int1 s201AV; |
|
|
119 |
int1 s201AZ; |
|
|
120 |
int1 s207AJ; |
|
|
121 |
int1 s203AJ; |
|
|
122 |
int1 s209AJ; |
|
|
123 |
int1 r207VU; |
|
|
124 |
int1 r207VD; |
2084 |
kakl |
125 |
int1 s202AN; |
|
|
126 |
int1 r202ND; |
|
|
127 |
int1 r202NU; |
|
|
128 |
int1 s205A; |
|
|
129 |
int1 s204AJ; |
|
|
130 |
int1 r204ZD; |
|
|
131 |
int1 r204ZU; |
2494 |
kakl |
132 |
int1 s208AN; |
|
|
133 |
int1 r208VU; |
|
|
134 |
int1 r208VD; |
|
|
135 |
int1 r208JU; |
|
|
136 |
int1 r208JD; |
|
|
137 |
int1 ispec; |
1746 |
kakl |
138 |
|
1747 |
kakl |
139 |
#bit CREN = 0xFAB.4 // USART enable register |
|
|
140 |
|
2494 |
kakl |
141 |
#define LED1 PIN_C0 // Vyvedeno na desku portu G |
|
|
142 |
#define LED2 PIN_C1 // Vyvedeno na desku portu G |
1746 |
kakl |
143 |
|
|
|
144 |
#define ON(port) output_low(port); |
|
|
145 |
#define OFF(port) output_high(port); |
|
|
146 |
|
2231 |
kakl |
147 |
typedef enum {RUN, STOP} roleta_state; |
|
|
148 |
roleta_state rol[18]; // Stavy rolet |
|
|
149 |
#define R103V 0 |
|
|
150 |
#define R110N 1 |
|
|
151 |
#define R104V 2 |
|
|
152 |
#define R104J 3 |
|
|
153 |
#define R207V 4 |
|
|
154 |
#define R202J 5 |
|
|
155 |
#define R204Z 6 |
2494 |
kakl |
156 |
#define R208V 7 |
|
|
157 |
#define R208J 8 |
2497 |
kakl |
158 |
#define R106J 9 |
|
|
159 |
#define R106Z 10 |
2499 |
kakl |
160 |
#define R105J 11 |
1746 |
kakl |
161 |
|
2232 |
kakl |
162 |
typedef enum {UP, DOWN, REVERS_UP, REVERS_DOWN, RUN_UP, RUN_DOWN, RUN_UP_WAITING} relay_state; |
2231 |
kakl |
163 |
relay_state relay; // Stavy rele |
1747 |
kakl |
164 |
|
2231 |
kakl |
165 |
int8 timer_run; // Bezpecnostni casovac behu rolety |
|
|
166 |
int8 timer_run_zaluzie; // Casovac zaluzie na preklopeni lamel |
|
|
167 |
int8 timer_revers; // Prodleva na vybiti kondenzatoru pa zastaveni rolety pred prepnutim rele |
|
|
168 |
int8 timer_start; // Prodleva na prepnuti rele pred startem rolety |
|
|
169 |
int8 timer; // Casovac komunikace |
2497 |
kakl |
170 |
int8 tS108; // Casovac svetlo spajz |
2231 |
kakl |
171 |
|
1747 |
kakl |
172 |
#int_TIMER0 |
|
|
173 |
void TIMER0_isr(void) |
|
|
174 |
{ |
1748 |
kakl |
175 |
if(timer>0) timer--; |
2497 |
kakl |
176 |
if(tS108>0) tS108--; |
2231 |
kakl |
177 |
if(timer_run>0) timer_run--; |
|
|
178 |
if(timer_revers>0) timer_revers--; |
|
|
179 |
if(timer_start>0) timer_start--; |
|
|
180 |
if(timer_run_zaluzie>0) timer_run_zaluzie--; |
2233 |
kakl |
181 |
output_toggle(LED2); |
1747 |
kakl |
182 |
} |
|
|
183 |
|
2231 |
kakl |
184 |
void stop_all() // Zastav vsechny rolety |
|
|
185 |
{ |
|
|
186 |
int8 n; |
|
|
187 |
|
|
|
188 |
output_a(0xFF); |
|
|
189 |
output_f(0xFF); |
2233 |
kakl |
190 |
for(n=0; n<18; n++) rol[n]=STOP; |
2231 |
kakl |
191 |
} |
|
|
192 |
|
|
|
193 |
void run_all() // Spust rolety |
|
|
194 |
{ |
|
|
195 |
if (rol[R103V]==RUN) ON(OR103V); |
|
|
196 |
if (rol[R110N]==RUN) ON(OR110N); |
|
|
197 |
if (rol[R104V]==RUN) ON(OR104V); |
|
|
198 |
if (rol[R104J]==RUN) ON(OR104J); |
|
|
199 |
if (rol[R207V]==RUN) ON(OR207V); |
|
|
200 |
if (rol[R202J]==RUN) ON(OR202J); |
|
|
201 |
if (rol[R204Z]==RUN) ON(OR204Z); |
2494 |
kakl |
202 |
if (rol[R208V]==RUN) ON(OR208V); |
|
|
203 |
if (rol[R208J]==RUN) ON(OR208J); |
2497 |
kakl |
204 |
if (rol[R106J]==RUN) ON(OR106J); |
|
|
205 |
if (rol[R106Z]==RUN) ON(OR106Z); |
2499 |
kakl |
206 |
if (rol[R105J]==RUN) ON(OR105J); |
2231 |
kakl |
207 |
} |
|
|
208 |
|
2232 |
kakl |
209 |
void run(int8 roleta) // Spust konkretni roletu |
1747 |
kakl |
210 |
{ |
2232 |
kakl |
211 |
switch (roleta) |
1747 |
kakl |
212 |
{ |
2232 |
kakl |
213 |
case R103V: ON(OR103V); break; |
|
|
214 |
case R110N: ON(OR110N); break; |
|
|
215 |
case R104V: ON(OR104V); break; |
|
|
216 |
case R104J: ON(OR104J); break; |
|
|
217 |
case R207V: ON(OR207V); break; |
|
|
218 |
case R202J: ON(OR202J); break; |
|
|
219 |
case R204Z: ON(OR204Z); break; |
2494 |
kakl |
220 |
case R208V: ON(OR208V); break; |
|
|
221 |
case R208J: ON(OR208J); break; |
2497 |
kakl |
222 |
case R106J: ON(OR106J); break; |
|
|
223 |
case R106Z: ON(OR106Z); break; |
2499 |
kakl |
224 |
case R105J: ON(OR105J); break; |
1747 |
kakl |
225 |
} |
|
|
226 |
} |
|
|
227 |
|
2233 |
kakl |
228 |
void stop(int8 roleta) // Spust konkretni roletu |
|
|
229 |
{ |
|
|
230 |
switch (roleta) |
|
|
231 |
{ |
|
|
232 |
case R103V: OFF(OR103V); break; |
|
|
233 |
case R110N: OFF(OR110N); break; |
|
|
234 |
case R104V: OFF(OR104V); break; |
|
|
235 |
case R104J: OFF(OR104J); break; |
|
|
236 |
case R207V: OFF(OR207V); break; |
|
|
237 |
case R202J: OFF(OR202J); break; |
|
|
238 |
case R204Z: OFF(OR204Z); break; |
2494 |
kakl |
239 |
case R208V: OFF(OR208V); break; |
|
|
240 |
case R208J: OFF(OR208J); break; |
2497 |
kakl |
241 |
case R106J: OFF(OR106J); break; |
|
|
242 |
case R106Z: OFF(OR106Z); break; |
2499 |
kakl |
243 |
case R105J: OFF(OR105J); break; |
2233 |
kakl |
244 |
} |
|
|
245 |
} |
|
|
246 |
|
2232 |
kakl |
247 |
void up(int8 roleta) // Pozadavek, aby roleta jela nahoru |
1747 |
kakl |
248 |
{ |
2232 |
kakl |
249 |
if (rol[roleta]==RUN) |
1747 |
kakl |
250 |
{ |
2232 |
kakl |
251 |
rol[roleta]=STOP; // Roleta jela, tak zastav |
2233 |
kakl |
252 |
stop(roleta); |
1747 |
kakl |
253 |
} |
2232 |
kakl |
254 |
else |
|
|
255 |
{ |
|
|
256 |
if ((relay==DOWN)||(relay==RUN_DOWN)) // Rele je prepnuto na druhou stranu! |
|
|
257 |
{ |
|
|
258 |
relay=REVERS_UP; // Reverzuj |
|
|
259 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
|
|
260 |
stop_all(); // Vsechno zastav |
|
|
261 |
} |
|
|
262 |
if (relay==RUN_UP) |
|
|
263 |
{ |
2233 |
kakl |
264 |
run(roleta); // Jede se spravnym smerem, tak jenom pust roletu |
2232 |
kakl |
265 |
} |
|
|
266 |
|
|
|
267 |
rol[roleta]=RUN; // Roleta stala, tak ji pust |
|
|
268 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
269 |
} |
1747 |
kakl |
270 |
} |
|
|
271 |
|
|
|
272 |
|
2232 |
kakl |
273 |
void down(int8 roleta) // Pozadavek, aby roleta jela dolu |
|
|
274 |
{ |
|
|
275 |
if (rol[roleta]==RUN) |
|
|
276 |
{ |
|
|
277 |
rol[roleta]=STOP; // Roleta jela, tak zastav |
2233 |
kakl |
278 |
stop(roleta); |
2232 |
kakl |
279 |
} |
|
|
280 |
else |
|
|
281 |
{ |
|
|
282 |
if ((relay==UP)||(relay==RUN_UP)||(relay==RUN_UP_WAITING)) // Rele je prepnuto na druhou stranu! |
|
|
283 |
{ |
|
|
284 |
relay=REVERS_DOWN; // Reverzuj |
|
|
285 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
|
|
286 |
stop_all(); // Vsechno zastav |
|
|
287 |
} |
|
|
288 |
if (relay==RUN_DOWN) |
|
|
289 |
{ |
2233 |
kakl |
290 |
run(roleta); // Jede se spravnym smerem, tak jenom pust roletu |
2232 |
kakl |
291 |
} |
|
|
292 |
|
|
|
293 |
rol[roleta]=RUN; // Roleta stala, tak ji pust |
|
|
294 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
295 |
} |
|
|
296 |
} |
|
|
297 |
|
|
|
298 |
|
1746 |
kakl |
299 |
void main() |
|
|
300 |
{ |
2085 |
kakl |
301 |
char buf[10]; // Buffer pro prijem prikazu |
2153 |
kakl |
302 |
unsigned int16 zakmity=0; // Osetreni zakmitu vypinacu |
1746 |
kakl |
303 |
|
1748 |
kakl |
304 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
305 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
306 |
setup_psp(PSP_DISABLED); |
|
|
307 |
setup_spi(SPI_SS_DISABLED); |
|
|
308 |
setup_wdt(WDT_OFF); |
2085 |
kakl |
309 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_8); |
1748 |
kakl |
310 |
setup_timer_1(T1_DISABLED); |
|
|
311 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
312 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
|
|
313 |
setup_ccp1(CCP_OFF); |
|
|
314 |
setup_comparator(NC_NC_NC_NC); |
|
|
315 |
setup_vref(FALSE); |
2085 |
kakl |
316 |
|
|
|
317 |
set_tris_a(0); // Vystupy |
|
|
318 |
set_tris_b(0); |
|
|
319 |
set_tris_e(0); |
|
|
320 |
set_tris_f(0); |
2494 |
kakl |
321 |
set_tris_g(0x20); |
2085 |
kakl |
322 |
set_tris_d(0xFF); // Vstupy |
|
|
323 |
set_tris_j(0xFF); |
2494 |
kakl |
324 |
set_tris_h(0xFF); |
1747 |
kakl |
325 |
|
2080 |
kakl |
326 |
output_a(0xFF); // Vsechno zhasni a zastav |
|
|
327 |
output_b(0xFF); |
|
|
328 |
output_f(0xFF); |
|
|
329 |
output_e(0xFF); |
2494 |
kakl |
330 |
output_g(0xFF); |
2231 |
kakl |
331 |
stop_all(); |
1747 |
kakl |
332 |
|
2232 |
kakl |
333 |
relay=RUN_UP_WAITING; // Rele je na zacatku vypnuto |
2231 |
kakl |
334 |
|
2081 |
kakl |
335 |
{ |
|
|
336 |
int n; |
|
|
337 |
|
|
|
338 |
for(n=0;n<10;n++) |
|
|
339 |
{ |
|
|
340 |
output_low(LED1); // Indikace restartu (pockame na nabiti kondenzatoru ve vstupnich obvodech) |
|
|
341 |
delay_ms(100); |
|
|
342 |
output_high(LED1); |
|
|
343 |
delay_ms(100); |
|
|
344 |
restart_wdt(); |
|
|
345 |
} |
|
|
346 |
} |
1746 |
kakl |
347 |
|
2080 |
kakl |
348 |
s201AV=IS201AV; // Precteme vychozi stav vypinacu |
|
|
349 |
s201AZ=IS201AZ; |
|
|
350 |
s207AJ=IS207AJ; |
|
|
351 |
s203AJ=IS203AJ; |
|
|
352 |
s209AJ=IS209AJ; |
|
|
353 |
r207VU=IR207VU; |
|
|
354 |
r207VD=IR207VD; |
2084 |
kakl |
355 |
s202AN=IS202AN; |
|
|
356 |
r202ND=IR202ND; |
|
|
357 |
r202NU=IR202NU; |
|
|
358 |
s205A=IS205A; |
|
|
359 |
s204AJ=IS204AJ; |
|
|
360 |
r204ZD=IR204ZD; |
|
|
361 |
r204ZU=IR204ZU; |
2494 |
kakl |
362 |
s208AN=IS208AN; |
|
|
363 |
r208VU=IR208VU; |
|
|
364 |
r208VD=IR208VD; |
|
|
365 |
r208JU=IR208JU; |
|
|
366 |
r208JD=IR208JD; |
|
|
367 |
ispec=Ispec; |
2232 |
kakl |
368 |
|
|
|
369 |
timer_run=0; // Zastav vsechny casovace |
|
|
370 |
timer=0; |
|
|
371 |
timer_revers=0; |
|
|
372 |
timer_start=0; |
|
|
373 |
timer_run_zaluzie=0; |
|
|
374 |
zakmity=0; |
|
|
375 |
|
2233 |
kakl |
376 |
enable_interrupts(INT_TIMER0); // Spust casovani |
1748 |
kakl |
377 |
enable_interrupts(GLOBAL); |
2081 |
kakl |
378 |
|
2232 |
kakl |
379 |
CREN=0; CREN=1; // Reinitialise USART |
|
|
380 |
|
1746 |
kakl |
381 |
while(TRUE) |
|
|
382 |
{ |
2085 |
kakl |
383 |
restart_wdt(); |
1748 |
kakl |
384 |
|
|
|
385 |
if(kbhit()) // Chce po nas nekdo neco? |
1746 |
kakl |
386 |
{ |
1748 |
kakl |
387 |
buf[0]=getc(); |
|
|
388 |
if((buf[0]=='S')||(buf[0]=='R')) // Jinym znakem nesmi zacinat prikaz |
1746 |
kakl |
389 |
{ |
1748 |
kakl |
390 |
int8 n=0; // Ukazatel do prijimaciho bufferu |
2231 |
kakl |
391 |
timer=T_RECEIVE; // Timeout pro prijem znaku |
1748 |
kakl |
392 |
|
|
|
393 |
do |
1746 |
kakl |
394 |
{ |
1748 |
kakl |
395 |
if(kbhit()) // Je dalsi znak? |
1747 |
kakl |
396 |
{ |
1748 |
kakl |
397 |
n++; |
|
|
398 |
buf[n]=getc(); |
1747 |
kakl |
399 |
} |
1748 |
kakl |
400 |
} while ((buf[n]!='\r')&&(timer>0)&&(n<7)); |
|
|
401 |
|
|
|
402 |
if (timer==0) { CREN=0; CREN=1; } // Reinitialise USART |
|
|
403 |
|
|
|
404 |
output_toggle(LED1); // Ukonceni prijimani prikazu |
|
|
405 |
|
|
|
406 |
if((timer>0)) |
1746 |
kakl |
407 |
{ |
1748 |
kakl |
408 |
|
|
|
409 |
if((buf[0]=='S')&&(n>=4)) // Zmena stavu svetla |
1747 |
kakl |
410 |
{ |
1748 |
kakl |
411 |
if(buf[1]=='1') |
|
|
412 |
{ |
|
|
413 |
switch(buf[2]) |
|
|
414 |
{ |
2499 |
kakl |
415 |
case '0': |
|
|
416 |
output_toggle(OS100A); |
|
|
417 |
break; |
1748 |
kakl |
418 |
case '2': |
2080 |
kakl |
419 |
output_toggle(OS102A); |
1748 |
kakl |
420 |
break; |
|
|
421 |
case '3': |
2080 |
kakl |
422 |
output_toggle(OS103J); |
1748 |
kakl |
423 |
break; |
|
|
424 |
case '4': |
2080 |
kakl |
425 |
output_toggle(OS104A); |
1748 |
kakl |
426 |
break; |
|
|
427 |
case '5': |
2080 |
kakl |
428 |
if(buf[3]=='A') {output_toggle(OS105A);} |
|
|
429 |
if(buf[3]=='Z') {output_toggle(OS105Z);} |
1748 |
kakl |
430 |
break; |
|
|
431 |
case '6': |
2080 |
kakl |
432 |
output_toggle(OS106A); |
1748 |
kakl |
433 |
break; |
|
|
434 |
case '7': |
2080 |
kakl |
435 |
output_toggle(OS107A); |
1748 |
kakl |
436 |
break; |
|
|
437 |
case '8': |
2080 |
kakl |
438 |
// output_toggle(OS108A); |
1748 |
kakl |
439 |
break; |
|
|
440 |
case '9': |
2080 |
kakl |
441 |
output_toggle(OS109A); |
1748 |
kakl |
442 |
break; |
|
|
443 |
case 'a': |
2499 |
kakl |
444 |
if(buf[3]=='A') {if(input(OS110V)) |
|
|
445 |
{ // Nesviti zrcadlo |
|
|
446 |
output_low(OS110J); output_low(OS110V); // Vsechno rozsvit |
|
|
447 |
} |
|
|
448 |
else |
|
|
449 |
{ // Sviti zrcadlo |
|
|
450 |
output_high(OS110J); output_high(OS110V); // Vsechno zhasni |
|
|
451 |
} |
|
|
452 |
} |
|
|
453 |
if(buf[3]=='B') {if(input(OS110J)) |
|
|
454 |
{ // Nesviti sprcha |
|
|
455 |
if(input(OS110V)) |
|
|
456 |
{ // Nesviti zrcadlo |
|
|
457 |
output_low(OS110J); // Rozsvit sprchu |
|
|
458 |
} |
|
|
459 |
else |
|
|
460 |
{ // Sviti zrcadlo |
|
|
461 |
output_low(OS110J); output_high(OS110V); // Rozsvit sprchu a zhasni zrcadlo |
|
|
462 |
} |
|
|
463 |
} |
|
|
464 |
else |
|
|
465 |
{ // Sviti sprcha |
|
|
466 |
output_high(OS110J); // Zhasni sprchu |
|
|
467 |
} |
|
|
468 |
} |
1748 |
kakl |
469 |
break; |
|
|
470 |
} |
|
|
471 |
} |
1747 |
kakl |
472 |
} |
1748 |
kakl |
473 |
|
|
|
474 |
if((buf[0]=='R')&&(n>=5)) // Zmena stavu rolety |
|
|
475 |
{ |
|
|
476 |
if(buf[1]=='1') |
|
|
477 |
{ |
|
|
478 |
switch(buf[2]) |
|
|
479 |
{ |
|
|
480 |
case '3': |
2233 |
kakl |
481 |
if(buf[4]=='U') {up(R103V);} else {down(R103V);} |
1748 |
kakl |
482 |
break; |
|
|
483 |
case '4': |
2233 |
kakl |
484 |
if(buf[3]=='V') if((buf[4]=='U')) {up(R104V);} else {down(R104V);} |
|
|
485 |
if(buf[3]=='J') if((buf[4]=='U')) {up(R104J);} else {down(R104J);} |
1748 |
kakl |
486 |
break; |
2499 |
kakl |
487 |
case '5': |
|
|
488 |
if(buf[3]=='J') if((buf[4]=='U')) {up(R105J);} else {down(R105J);} |
|
|
489 |
break; |
2497 |
kakl |
490 |
case '6': |
|
|
491 |
if(buf[3]=='J') if((buf[4]=='U')) {up(R106J);} else {down(R106J);} |
|
|
492 |
if(buf[3]=='Z') if((buf[4]=='U')) {up(R106Z);} else {down(R106Z);} |
|
|
493 |
break; |
1748 |
kakl |
494 |
case 'a': |
2233 |
kakl |
495 |
if((buf[4]=='U')) |
|
|
496 |
{//up(R110N); |
|
|
497 |
if ((relay==DOWN)||(relay==RUN_DOWN)) // Rele je prepnuto na druhou stranu! |
|
|
498 |
{ |
|
|
499 |
relay=REVERS_UP; // Reverzuj |
|
|
500 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
|
|
501 |
stop_all(); // Vsechno zastav |
|
|
502 |
} |
|
|
503 |
if (relay==RUN_UP) |
|
|
504 |
{ |
|
|
505 |
run(R110N); // Jede se spravnym smerem, tak jenom pust roletu |
|
|
506 |
} |
|
|
507 |
|
|
|
508 |
rol[R110N]=RUN; // Roleta stala, tak ji pust |
|
|
509 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
510 |
} |
|
|
511 |
else |
|
|
512 |
{//down(R110N); |
|
|
513 |
if ((relay==UP)||(relay==RUN_UP)||(relay==RUN_UP_WAITING)) // Rele je prepnuto na druhou stranu! |
|
|
514 |
{ |
|
|
515 |
relay=REVERS_DOWN; // Reverzuj |
|
|
516 |
timer_revers=T_REVERS; // Natahni casovac na vybiti kondenzatoru a reverz motoru |
|
|
517 |
stop_all(); // Vsechno zastav |
|
|
518 |
} |
|
|
519 |
if (relay==RUN_DOWN) |
|
|
520 |
{ |
|
|
521 |
run(R110N); // Jede se spravnym smerem, tak jenom pust roletu |
|
|
522 |
} |
|
|
523 |
|
|
|
524 |
rol[R110N]=RUN; // Roleta stala, tak ji pust |
|
|
525 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
526 |
} |
|
|
527 |
timer_run_zaluzie=T_GO_ZALUZIE; |
1748 |
kakl |
528 |
break; |
|
|
529 |
} |
|
|
530 |
} |
|
|
531 |
} |
|
|
532 |
|
1746 |
kakl |
533 |
} |
|
|
534 |
} |
|
|
535 |
} |
1748 |
kakl |
536 |
|
2080 |
kakl |
537 |
// mistni vypinace z 2. n.p. |
2085 |
kakl |
538 |
if (0==zakmity) |
|
|
539 |
{ |
|
|
540 |
if(s201AV!=IS201AV) {s201AV=IS201AV; output_toggle(OS102A); zakmity=ZAKMIT;} |
|
|
541 |
if(s201AZ!=IS201AZ) {s201AZ=IS201AZ; output_toggle(OS102A); zakmity=ZAKMIT;} |
|
|
542 |
if(s207AJ!=IS207AJ) {s207AJ=IS207AJ; output_toggle(OS207A); zakmity=ZAKMIT;} |
|
|
543 |
if(s203AJ!=IS203AJ) {s203AJ=IS203AJ; output_toggle(OS203A); zakmity=ZAKMIT;} |
|
|
544 |
if(s209AJ!=IS209AJ) {s209AJ=IS209AJ; output_toggle(OS209A); zakmity=ZAKMIT;} |
2233 |
kakl |
545 |
if(s205A!=IS205A) {s205A=IS205A; output_toggle(OS205A); zakmity=ZAKMIT;} |
2085 |
kakl |
546 |
if(s204AJ!=IS204AJ) {s204AJ=IS204AJ; output_toggle(OS204A); zakmity=ZAKMIT;} |
|
|
547 |
if(s202AN!=IS202AN) {s202AN=IS202AN; output_toggle(OS202A); zakmity=ZAKMIT;} |
2494 |
kakl |
548 |
if(s208AN!=IS208AN) {s208AN=IS208AN; output_toggle(OS208A); zakmity=ZAKMIT;} |
2085 |
kakl |
549 |
|
2232 |
kakl |
550 |
if(r207VU!=IR207VU) {r207VU=IR207VU; up(R207V); zakmity=ZAKMIT;} |
|
|
551 |
if(r207VD!=IR207VD) {r207VD=IR207VD; down(R207V); zakmity=ZAKMIT;} |
2233 |
kakl |
552 |
if(r202NU!=IR202NU) {r202NU=IR202NU; up(R202J); zakmity=ZAKMIT;} |
2232 |
kakl |
553 |
if(r202ND!=IR202ND) {r202ND=IR202ND; down(R202J); zakmity=ZAKMIT;} |
2233 |
kakl |
554 |
if(r204ZU!=IR204ZU) {r204ZU=IR204ZU; up(R204Z); zakmity=ZAKMIT;} |
2232 |
kakl |
555 |
if(r204ZD!=IR204ZD) {r204ZD=IR204ZD; down(R204Z); zakmity=ZAKMIT;} |
2494 |
kakl |
556 |
if(r208VU!=IR208VU) {r208VU=IR208VU; up(R208V); zakmity=ZAKMIT;} |
|
|
557 |
if(r208VD!=IR208VD) {r208VD=IR208VD; down(R208V); zakmity=ZAKMIT;} |
|
|
558 |
if(r208JU!=IR208JU) {r208JU=IR208JU; up(R208J); zakmity=ZAKMIT;} |
|
|
559 |
if(r208JD!=IR208JD) {r208JD=IR208JD; down(R208J); zakmity=ZAKMIT;} |
|
|
560 |
|
2499 |
kakl |
561 |
//!!! if(ispec!=Ispec) {ispec=Ispec; output_toggle(OS100A); zakmity=ZAKMIT;} |
2085 |
kakl |
562 |
} |
|
|
563 |
else zakmity--; |
2232 |
kakl |
564 |
|
2497 |
kakl |
565 |
// Spajz mikrospinac i svetlo |
|
|
566 |
if(IS108A) {output_high(OS108A); tS108=TIMEOUT_SPAJZ;} |
|
|
567 |
if((!IS108A)&&(tS108>0)) {output_low(OS108A);} else {output_high(OS108A);} |
|
|
568 |
|
2232 |
kakl |
569 |
switch (relay) |
|
|
570 |
{ |
|
|
571 |
case UP: |
|
|
572 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
|
|
573 |
{ |
|
|
574 |
relay=RUN_UP; // Zmen stav na "jede se" |
|
|
575 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
|
|
576 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
577 |
} |
|
|
578 |
break; |
2231 |
kakl |
579 |
|
2232 |
kakl |
580 |
case DOWN: |
|
|
581 |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
|
|
582 |
{ |
|
|
583 |
relay=RUN_DOWN; // Zmen stav na "jede se" |
|
|
584 |
run_all(); // Sepni triaky u rolet, ktere maji jet |
|
|
585 |
timer_run=T_GO; // Natahni bezpecnostni casovac |
|
|
586 |
} |
|
|
587 |
break; |
|
|
588 |
|
|
|
589 |
case RUN_UP: |
|
|
590 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
|
|
591 |
{ |
|
|
592 |
timer=RUN_UP_WAITING; |
|
|
593 |
stop_all(); // Vsechno zastav |
|
|
594 |
} |
|
|
595 |
break; |
|
|
596 |
|
|
|
597 |
case RUN_DOWN: |
|
|
598 |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
|
|
599 |
{ |
|
|
600 |
relay=REVERS_UP; // Vsechno zastav a reverzuj pro prepnuti rele do klidove polohy bez energizace civky |
|
|
601 |
stop_all(); |
|
|
602 |
timer_revers=T_REVERS; |
|
|
603 |
} |
|
|
604 |
break; |
|
|
605 |
|
|
|
606 |
case REVERS_UP: |
|
|
607 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
|
|
608 |
{ |
|
|
609 |
relay=UP; // Prepni rele |
|
|
610 |
OFF(RE); |
|
|
611 |
timer_start=T_START; // Pockej na prepnuti rele |
|
|
612 |
} |
|
|
613 |
break; |
|
|
614 |
|
|
|
615 |
case REVERS_DOWN: |
|
|
616 |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
|
|
617 |
{ |
|
|
618 |
relay=DOWN; // Prepni rele |
|
|
619 |
ON(RE); |
|
|
620 |
timer_start=T_START; // Pockej na prepnuti rele |
|
|
621 |
} |
|
|
622 |
break; |
|
|
623 |
} |
2233 |
kakl |
624 |
|
|
|
625 |
// Zaluzie ma kratsi beh |
|
|
626 |
if ((timer_run_zaluzie==0)&&(rol[R110N]==RUN)) {rol[R110N]=STOP; OFF(OR110N);} |
2231 |
kakl |
627 |
} |
1746 |
kakl |
628 |
} |