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 |
|
|
|
12 |
[CAN] |
|
|
13 |
[IN J] [IN D] |
|
|
14 |
[OUT A] [CPU] |
|
|
15 |
|
|
|
16 |
[OUT F] [OUT B] [OUT E] |
|
|
17 |
|
2080 |
kakl |
18 |
*/ |
1746 |
kakl |
19 |
#include "main.h" |
|
|
20 |
|
|
|
21 |
#case |
|
|
22 |
|
1749 |
kakl |
23 |
#define REVERS 3 // 2*256 ms = 0,75 s |
1747 |
kakl |
24 |
#define GO 117 // 117*256 ms = 30 s |
1749 |
kakl |
25 |
#define GO_ZALUZIE 6 // cca 1,5 s |
|
|
26 |
#define RECEIVE 10 // cca 2,6 s |
1747 |
kakl |
27 |
|
2080 |
kakl |
28 |
#define OR110NU PIN_A0 //* t1 Zaluzie koupelna dole |
|
|
29 |
#define OR110ND PIN_A1 //* t2 |
|
|
30 |
#define OR207VU PIN_A2 // t3 Roleta klubovna |
|
|
31 |
#define OR207VD PIN_A3 // t4 |
|
|
32 |
#define OR103VU PIN_A4 // t5 Roleta loznice |
|
|
33 |
#define OR103VD PIN_A5 // t6 |
|
|
34 |
//#define OR104VU PIN_A4 // Roleta laborator vychod |
|
|
35 |
//#define OR104VD PIN_A5 |
|
|
36 |
#define OR104JU PIN_A6 // t7 Roleta laborator jih |
|
|
37 |
#define OR104JD PIN_A7 // t8 |
1746 |
kakl |
38 |
|
2080 |
kakl |
39 |
#define OS103J PIN_B0 // t1 Svetla loznice |
|
|
40 |
#define OS105Z PIN_B1 // t2 Svetlo kuchyn nad lavici |
|
|
41 |
#define OS110N PIN_B2 // t3 Svetlo koupelna dole zachod |
|
|
42 |
#define OS106A PIN_B3 // t4 Svetlo trucovna stred |
|
|
43 |
#define OS107A PIN_B4 // t5 Svetlo satna |
|
|
44 |
#define OS109A PIN_B5 // t6 Svetlo technologicka mistnost |
|
|
45 |
//#define OS110J PIN_B6 // t7 Svetlo koupelna dole sprcha |
|
|
46 |
//#define O... PIN_B7 // t8 |
1746 |
kakl |
47 |
|
|
|
48 |
//#define OS105C PIN_C2 |
|
|
49 |
//#define PIN_C3 31763 |
|
|
50 |
//#define PIN_C4 31764 |
|
|
51 |
//#define PIN_C5 31765 |
|
|
52 |
//#define PIN_C6 31766 //TX |
|
|
53 |
//#define PIN_C7 31767 //RX |
|
|
54 |
|
2081 |
kakl |
55 |
#define OR104VU PIN_F0 // t1 Roleta laborator vychod |
|
|
56 |
#define OR104VD PIN_F1 // t2 |
2080 |
kakl |
57 |
//#define O... PIN_F2 // t3 |
|
|
58 |
//#define O... PIN_F3 // t4 |
|
|
59 |
//#define O... PIN_F4 // t5 |
|
|
60 |
//#define O... PIN_F5 // t6 |
|
|
61 |
//#define O... PIN_F6 // t7 |
|
|
62 |
//#define O... PIN_F7 // t8 |
1746 |
kakl |
63 |
|
2080 |
kakl |
64 |
//#define I.... input(PIN_D0) // A |
|
|
65 |
#define IS201AZ input(PIN_D1) // B Vypinac chodba 2.n.p. zapad u Kaklika |
|
|
66 |
#define IS207AJ input(PIN_D2) // C Vypinac klubovna |
2081 |
kakl |
67 |
#define IR207VD input(PIN_D3) // D Vypinac roleta klubovna dolu |
|
|
68 |
#define IR207VU input(PIN_D4) // E Vypinac roleta klubovna nahoru |
2080 |
kakl |
69 |
#define IS201AV input(PIN_D5) // F Vypinac chodba 2.n.p. vychod |
|
|
70 |
#define IS209AJ input(PIN_D6) // G Vypinac koupelna Zizala |
|
|
71 |
#define IS203AJ input(PIN_D7) // H Vypinac koupelna Kaklik |
1746 |
kakl |
72 |
|
2080 |
kakl |
73 |
#define OS102A PIN_E0 // t1 Svetlo chodba |
|
|
74 |
#define OS105A PIN_E1 //* t2 Svetlo kuchyne stred |
|
|
75 |
#define OS207A PIN_E2 // t3 Svetlo klubovna |
|
|
76 |
#define OS104A PIN_E3 //* t4 Svetlo laborator |
|
|
77 |
//#define O... PIN_E4 // t5 |
|
|
78 |
#define OS209A PIN_E5 // t6 Svetlo Zizala koupelna |
|
|
79 |
#define OS203A PIN_E6 // t7 Svetlo Kaklik koupelna |
|
|
80 |
//#define O... PIN_E7 // t8 |
1746 |
kakl |
81 |
|
2080 |
kakl |
82 |
int1 s201AV; |
|
|
83 |
int1 s201AZ; |
|
|
84 |
int1 s207AJ; |
|
|
85 |
int1 s203AJ; |
|
|
86 |
int1 s209AJ; |
|
|
87 |
int1 r207VU; |
|
|
88 |
int1 r207VD; |
1746 |
kakl |
89 |
|
1747 |
kakl |
90 |
#bit CREN = 0xFAB.4 // USART enable register |
|
|
91 |
|
2080 |
kakl |
92 |
#define LED1 PIN_C0 |
|
|
93 |
#define LED2 PIN_C1 |
1746 |
kakl |
94 |
|
|
|
95 |
#define ON(port) output_low(port); |
|
|
96 |
#define OFF(port) output_high(port); |
|
|
97 |
|
1747 |
kakl |
98 |
typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
1746 |
kakl |
99 |
|
2080 |
kakl |
100 |
state r103V, r110N, r104V, r104J, r207V; // Stavy rolet |
|
|
101 |
int8 tr103V, tr110N, tr104V, tr104J, tr207V; // Casovace rolet |
1748 |
kakl |
102 |
int8 timer; // Casovac komunikace |
1747 |
kakl |
103 |
|
|
|
104 |
#int_TIMER0 |
|
|
105 |
void TIMER0_isr(void) |
|
|
106 |
{ |
1748 |
kakl |
107 |
if(tr103V>0) tr103V--; |
|
|
108 |
if(tr110N>0) tr110N--; |
|
|
109 |
if(tr104V>0) tr104V--; |
|
|
110 |
if(tr104J>0) tr104J--; |
2080 |
kakl |
111 |
if(tr207V>0) tr207V--; |
1748 |
kakl |
112 |
if(timer>0) timer--; |
1747 |
kakl |
113 |
output_toggle(LED2); |
|
|
114 |
} |
|
|
115 |
|
|
|
116 |
void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
|
|
117 |
{ |
|
|
118 |
switch (*status) |
|
|
119 |
{ |
|
|
120 |
case STOP: |
|
|
121 |
case GO_DOWN: |
|
|
122 |
*status=REVERS_UP; |
|
|
123 |
*timer=REVERS; |
|
|
124 |
break; |
|
|
125 |
case REVERS_UP: |
|
|
126 |
case GO_UP: |
|
|
127 |
*status=STOP; |
|
|
128 |
*timer=0; |
|
|
129 |
break; |
|
|
130 |
} |
|
|
131 |
} |
|
|
132 |
|
|
|
133 |
void down(state *status, int8 *timer) // Zmena stavu rolety smer dolu |
|
|
134 |
{ |
|
|
135 |
switch (*status) |
|
|
136 |
{ |
|
|
137 |
case STOP: |
|
|
138 |
case GO_UP: |
|
|
139 |
*status=REVERS_DOWN; |
|
|
140 |
*timer=REVERS; |
|
|
141 |
break; |
|
|
142 |
case REVERS_DOWN: |
|
|
143 |
case GO_DOWN: |
|
|
144 |
*status=STOP; |
|
|
145 |
*timer=0; |
|
|
146 |
break; |
|
|
147 |
} |
|
|
148 |
} |
|
|
149 |
|
|
|
150 |
#define run(x) { \ |
|
|
151 |
switch(r##x) \ |
|
|
152 |
{ \ |
|
|
153 |
case STOP: \ |
2080 |
kakl |
154 |
OFF(OR##x##U); \ |
|
|
155 |
OFF(OR##x##D); \ |
1747 |
kakl |
156 |
break; \ |
|
|
157 |
case GO_UP: \ |
2080 |
kakl |
158 |
OFF(OR##x##D); \ |
|
|
159 |
ON(OR##x##U); \ |
1747 |
kakl |
160 |
if(tr##x==0) {r##x=STOP;} \ |
|
|
161 |
break; \ |
|
|
162 |
case GO_DOWN: \ |
2080 |
kakl |
163 |
OFF(OR##x##U); \ |
|
|
164 |
ON(OR##x##D); \ |
1747 |
kakl |
165 |
if(tr##x==0) {r##x=STOP;} \ |
|
|
166 |
break; \ |
|
|
167 |
case REVERS_UP: \ |
2080 |
kakl |
168 |
OFF(OR##x##U); \ |
|
|
169 |
OFF(OR##x##D); \ |
1747 |
kakl |
170 |
if(tr##x==0) {r##x=GO_UP; tr##x=GO;} \ |
|
|
171 |
break; \ |
|
|
172 |
case REVERS_DOWN: \ |
2080 |
kakl |
173 |
OFF(OR##x##U); \ |
|
|
174 |
OFF(OR##x##D); \ |
1747 |
kakl |
175 |
if(tr##x==0) {r##x=GO_DOWN; tr##x=GO;} \ |
|
|
176 |
break; \ |
|
|
177 |
} \ |
|
|
178 |
} |
|
|
179 |
|
1746 |
kakl |
180 |
void main() |
|
|
181 |
{ |
1748 |
kakl |
182 |
char buf[10]; |
1746 |
kakl |
183 |
|
1748 |
kakl |
184 |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
|
|
185 |
setup_adc(ADC_CLOCK_DIV_2); |
|
|
186 |
setup_psp(PSP_DISABLED); |
|
|
187 |
setup_spi(SPI_SS_DISABLED); |
|
|
188 |
setup_wdt(WDT_OFF); |
|
|
189 |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
|
|
190 |
setup_timer_1(T1_DISABLED); |
|
|
191 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
192 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
|
|
193 |
setup_ccp1(CCP_OFF); |
|
|
194 |
setup_comparator(NC_NC_NC_NC); |
|
|
195 |
setup_vref(FALSE); |
1747 |
kakl |
196 |
|
2080 |
kakl |
197 |
output_a(0xFF); // Vsechno zhasni a zastav |
|
|
198 |
output_b(0xFF); |
|
|
199 |
output_f(0xFF); |
|
|
200 |
output_e(0xFF); |
1747 |
kakl |
201 |
|
1748 |
kakl |
202 |
r103V=STOP; // Rolety jsou zastaveny |
|
|
203 |
r110N=STOP; |
|
|
204 |
r104V=STOP; |
|
|
205 |
r104J=STOP; |
2080 |
kakl |
206 |
r207V=STOP; |
1749 |
kakl |
207 |
tr103V=0; |
|
|
208 |
tr110N=0; |
|
|
209 |
tr104V=0; |
|
|
210 |
tr104J=0; |
2080 |
kakl |
211 |
tr207V=0; |
1749 |
kakl |
212 |
|
2081 |
kakl |
213 |
{ |
|
|
214 |
int n; |
|
|
215 |
|
|
|
216 |
for(n=0;n<10;n++) |
|
|
217 |
{ |
|
|
218 |
output_low(LED1); // Indikace restartu (pockame na nabiti kondenzatoru ve vstupnich obvodech) |
|
|
219 |
delay_ms(100); |
|
|
220 |
output_high(LED1); |
|
|
221 |
delay_ms(100); |
|
|
222 |
restart_wdt(); |
|
|
223 |
} |
|
|
224 |
} |
1746 |
kakl |
225 |
|
2080 |
kakl |
226 |
s201AV=IS201AV; // Precteme vychozi stav vypinacu |
|
|
227 |
s201AZ=IS201AZ; |
|
|
228 |
s207AJ=IS207AJ; |
|
|
229 |
s203AJ=IS203AJ; |
|
|
230 |
s209AJ=IS209AJ; |
|
|
231 |
r207VU=IR207VU; |
|
|
232 |
r207VD=IR207VD; |
2081 |
kakl |
233 |
|
|
|
234 |
CREN=0; CREN=1; // Reinitialise USART |
2080 |
kakl |
235 |
|
1748 |
kakl |
236 |
enable_interrupts(INT_TIMER0); |
|
|
237 |
enable_interrupts(GLOBAL); |
2081 |
kakl |
238 |
|
1746 |
kakl |
239 |
while(TRUE) |
|
|
240 |
{ |
1748 |
kakl |
241 |
|
|
|
242 |
if(kbhit()) // Chce po nas nekdo neco? |
1746 |
kakl |
243 |
{ |
1748 |
kakl |
244 |
buf[0]=getc(); |
|
|
245 |
if((buf[0]=='S')||(buf[0]=='R')) // Jinym znakem nesmi zacinat prikaz |
1746 |
kakl |
246 |
{ |
1748 |
kakl |
247 |
int8 n=0; // Ukazatel do prijimaciho bufferu |
|
|
248 |
timer=RECEIVE; // Timeout pro prijem znaku |
|
|
249 |
|
|
|
250 |
do |
1746 |
kakl |
251 |
{ |
1748 |
kakl |
252 |
if(kbhit()) // Je dalsi znak? |
1747 |
kakl |
253 |
{ |
1748 |
kakl |
254 |
n++; |
|
|
255 |
buf[n]=getc(); |
1747 |
kakl |
256 |
} |
1748 |
kakl |
257 |
} while ((buf[n]!='\r')&&(timer>0)&&(n<7)); |
|
|
258 |
|
|
|
259 |
if (timer==0) { CREN=0; CREN=1; } // Reinitialise USART |
|
|
260 |
|
|
|
261 |
output_toggle(LED1); // Ukonceni prijimani prikazu |
|
|
262 |
|
|
|
263 |
if((timer>0)) |
1746 |
kakl |
264 |
{ |
1748 |
kakl |
265 |
|
|
|
266 |
if((buf[0]=='S')&&(n>=4)) // Zmena stavu svetla |
1747 |
kakl |
267 |
{ |
1748 |
kakl |
268 |
if(buf[1]=='1') |
|
|
269 |
{ |
|
|
270 |
switch(buf[2]) |
|
|
271 |
{ |
|
|
272 |
case '2': |
2080 |
kakl |
273 |
output_toggle(OS102A); |
1748 |
kakl |
274 |
break; |
|
|
275 |
case '3': |
2080 |
kakl |
276 |
output_toggle(OS103J); |
1748 |
kakl |
277 |
break; |
|
|
278 |
case '4': |
2080 |
kakl |
279 |
output_toggle(OS104A); |
1748 |
kakl |
280 |
break; |
|
|
281 |
case '5': |
2080 |
kakl |
282 |
if(buf[3]=='A') {output_toggle(OS105A);} |
|
|
283 |
if(buf[3]=='Z') {output_toggle(OS105Z);} |
1748 |
kakl |
284 |
break; |
|
|
285 |
case '6': |
2080 |
kakl |
286 |
output_toggle(OS106A); |
1748 |
kakl |
287 |
break; |
|
|
288 |
case '7': |
2080 |
kakl |
289 |
output_toggle(OS107A); |
1748 |
kakl |
290 |
break; |
|
|
291 |
case '8': |
2080 |
kakl |
292 |
// output_toggle(OS108A); |
1748 |
kakl |
293 |
break; |
|
|
294 |
case '9': |
2080 |
kakl |
295 |
output_toggle(OS109A); |
1748 |
kakl |
296 |
break; |
|
|
297 |
case 'a': |
2080 |
kakl |
298 |
// output_toggle(OS110J); |
|
|
299 |
output_toggle(OS110N); |
1748 |
kakl |
300 |
break; |
|
|
301 |
} |
|
|
302 |
} |
1747 |
kakl |
303 |
} |
1748 |
kakl |
304 |
|
|
|
305 |
if((buf[0]=='R')&&(n>=5)) // Zmena stavu rolety |
|
|
306 |
{ |
|
|
307 |
if(buf[1]=='1') |
|
|
308 |
{ |
|
|
309 |
switch(buf[2]) |
|
|
310 |
{ |
|
|
311 |
case '3': |
|
|
312 |
if(buf[4]=='U') {up(&r103V,&tr103V);} else {down(&r103V,&tr103V);} |
|
|
313 |
break; |
|
|
314 |
case '4': |
|
|
315 |
if(buf[3]=='V') if((buf[4]=='U')) {up(&r104V,&tr104V);} else {down(&r104V,&tr104V);} |
|
|
316 |
if(buf[3]=='J') if((buf[4]=='U')) {up(&r104J,&tr104J);} else {down(&r104J,&tr104J);} |
|
|
317 |
break; |
|
|
318 |
case 'a': |
|
|
319 |
if((buf[4]=='U')) {up(&r110N,&tr110N);} else {down(&r110N,&tr110N);} |
|
|
320 |
break; |
|
|
321 |
} |
|
|
322 |
} |
|
|
323 |
} |
|
|
324 |
|
1746 |
kakl |
325 |
} |
|
|
326 |
} |
|
|
327 |
} |
1748 |
kakl |
328 |
|
|
|
329 |
run(103V); // Rizeni rolet za behu |
2080 |
kakl |
330 |
// run(104V); |
1748 |
kakl |
331 |
run(104J); |
2080 |
kakl |
332 |
run(207V); |
1747 |
kakl |
333 |
|
1748 |
kakl |
334 |
switch(r110N) // Zaluzie ma specielni rizeni |
|
|
335 |
{ |
|
|
336 |
case STOP: |
2080 |
kakl |
337 |
OFF(OR110NU); |
|
|
338 |
OFF(OR110ND); |
1748 |
kakl |
339 |
break; |
|
|
340 |
case GO_UP: |
2080 |
kakl |
341 |
OFF(OR110ND); |
|
|
342 |
ON(OR110NU); |
1748 |
kakl |
343 |
if(tr110N==0) {r110N=STOP;} |
|
|
344 |
break; |
|
|
345 |
case GO_DOWN: |
2080 |
kakl |
346 |
OFF(OR110NU); |
|
|
347 |
ON(OR110ND); |
1748 |
kakl |
348 |
if(tr110N==0) {r110N=STOP;} |
|
|
349 |
break; |
|
|
350 |
case REVERS_UP: |
2080 |
kakl |
351 |
OFF(OR110NU); |
|
|
352 |
OFF(OR110ND); |
1749 |
kakl |
353 |
if(tr110N==0) {r110N=GO_UP; tr110N=GO_ZALUZIE;} // Nahoru pouze kratce na otevreni zaluzie |
1748 |
kakl |
354 |
break; |
|
|
355 |
case REVERS_DOWN: |
2080 |
kakl |
356 |
OFF(OR110NU); |
|
|
357 |
OFF(OR110ND); |
|
|
358 |
if(tr110N==0) {r110N=GO_DOWN; tr110N=GO_ZALUZIE;} // Dolu take kratce pouze na zaklopeni zaluzie |
1748 |
kakl |
359 |
break; |
|
|
360 |
} |
2080 |
kakl |
361 |
|
|
|
362 |
// mistni vypinace z 2. n.p. |
|
|
363 |
if(s201AV!=IS201AV) {s201AV=IS201AV; output_toggle(OS102A); delay_ms(100); continue;} |
|
|
364 |
if(s201AZ!=IS201AZ) {s201AZ=IS201AZ; output_toggle(OS102A); delay_ms(100); continue;} |
|
|
365 |
if(s207AJ!=IS207AJ) {s207AJ=IS207AJ; output_toggle(OS207A); delay_ms(100); continue;} |
|
|
366 |
if(s203AJ!=IS203AJ) {s203AJ=IS203AJ; output_toggle(OS203A); delay_ms(100); continue;} |
|
|
367 |
if(s209AJ!=IS209AJ) {s209AJ=IS209AJ; output_toggle(OS209A); delay_ms(100); continue;} |
|
|
368 |
|
2081 |
kakl |
369 |
if(r207VU!=IR207VU) {r207VU=IR207VU; up(&r207V,&tr207V); delay_ms(100); continue;} |
|
|
370 |
if(r207VD!=IR207VD) {r207VD=IR207VD; down(&r207V,&tr207V); delay_ms(100); continue;} |
2080 |
kakl |
371 |
|
1748 |
kakl |
372 |
restart_wdt(); |
1746 |
kakl |
373 |
} |
|
|
374 |
} |