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