Rev 1747 | Rev 1748 | ||
---|---|---|---|
Line 3... | Line 3... | ||
3 | #case |
3 | #case |
4 | |
4 | |
5 | #define REVERS 2 // 2*256 ms = 0,5 s |
5 | #define REVERS 2 // 2*256 ms = 0,5 s |
6 | #define GO 117 // 117*256 ms = 30 s |
6 | #define GO 117 // 117*256 ms = 30 s |
7 | #define GO_ZALUZIE 5 // 5*256 ms = 1,25 s |
7 | #define GO_ZALUZIE 5 // 5*256 ms = 1,25 s |
- | 8 | #define RECEIVE 12 // 3 s |
|
8 | |
9 | |
9 | #define S105A PIN_A0 |
10 | #define S105A PIN_A0 |
10 | #define R110AU PIN_A1 |
11 | #define R110NU PIN_A1 |
11 | #define R110AD PIN_A2 |
12 | #define R110ND PIN_A2 |
12 | #define S104A PIN_A3 |
13 | #define S104A PIN_A3 |
13 | #define R104AU PIN_A4 |
14 | #define R104VU PIN_A4 |
14 | #define R104AD PIN_A5 |
15 | #define R104VD PIN_A5 |
15 | #define R104BU PIN_A6 |
16 | #define R104JU PIN_A6 |
16 | #define R104BD PIN_A7 |
17 | #define R104JD PIN_A7 |
17 | |
18 | |
18 | #define S103A PIN_B0 |
19 | #define S103J PIN_B0 |
19 | #define R103AU PIN_B1 |
20 | #define R103VU PIN_B1 |
20 | #define R103AD PIN_B2 |
21 | #define R103VD PIN_B2 |
21 | #define S106A PIN_B3 |
22 | #define S106A PIN_B3 |
22 | #define S107A PIN_B4 |
23 | #define S107A PIN_B4 |
23 | #define S109A PIN_B5 |
24 | #define S109A PIN_B5 |
24 | |
25 | |
25 | //#define OS101 PIN_C0 |
26 | //#define OS101 PIN_C0 |
Line 30... | Line 31... | ||
30 | //#define PIN_C5 31765 |
31 | //#define PIN_C5 31765 |
31 | |
32 | |
32 | //#define PIN_C6 31766 //TX |
33 | //#define PIN_C6 31766 //TX |
33 | //#define PIN_C7 31767 //RX |
34 | //#define PIN_C7 31767 //RX |
34 | |
35 | |
35 | #define S101A PIN_D0 |
36 | //#define S101A PIN_F0 |
36 | #define S105D PIN_D1 |
37 | #define S105Z PIN_F1 |
37 | #define S102A PIN_D2 |
38 | #define S102A PIN_F2 |
38 | #define S110C PIN_D3 |
39 | #define S110N PIN_F3 |
39 | #define S108A PIN_D4 |
40 | #define S108A PIN_F4 |
40 | #define S201A PIN_D5 |
41 | #define S201A PIN_F5 |
41 | #define S110B PIN_D6 |
42 | #define S110J PIN_F6 |
42 | |
43 | |
43 | /* |
44 | /* |
44 | #define PIN_E0 31776 |
45 | #define PIN_E0 31776 |
45 | #define PIN_E1 31777 |
46 | #define PIN_E1 31777 |
46 | #define PIN_E2 31778 |
47 | #define PIN_E2 31778 |
Line 93... | Line 94... | ||
93 | #define ON(port) output_low(port); |
94 | #define ON(port) output_low(port); |
94 | #define OFF(port) output_high(port); |
95 | #define OFF(port) output_high(port); |
95 | |
96 | |
96 | typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
97 | typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
97 | |
98 | |
98 | state r103A, r110A, r104A, r104B; // Stavy rolet |
99 | state r103V, r110N, r104V, r104J; // Stavy rolet |
99 | int8 tr103A, tr110A, tr104A, tr104B; // Casovace rolet |
100 | int8 tr103V, tr110N, tr104V, tr104J; // Casovace rolet |
- | 101 | int8 timer; // Casovac komunikace |
|
100 | |
102 | |
101 | #int_TIMER0 |
103 | #int_TIMER0 |
102 | void TIMER0_isr(void) |
104 | void TIMER0_isr(void) |
103 | { |
105 | { |
104 | if(tr103A>0) tr103A--; |
106 | if(tr103V>0) tr103V--; |
105 | if(tr110A>0) tr110A--; |
107 | if(tr110N>0) tr110N--; |
106 | if(tr104A>0) tr104A--; |
108 | if(tr104V>0) tr104V--; |
107 | if(tr104B>0) tr104B--; |
109 | if(tr104J>0) tr104J--; |
- | 110 | if(timer>0) timer--; |
|
108 | output_toggle(LED2); |
111 | output_toggle(LED2); |
109 | } |
112 | } |
110 | |
113 | |
111 | void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
114 | void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
112 | { |
115 | { |
Line 172... | Line 175... | ||
172 | } \ |
175 | } \ |
173 | } |
176 | } |
174 | |
177 | |
175 | void main() |
178 | void main() |
176 | { |
179 | { |
177 | char c; |
180 | char buf[10]; |
178 | |
181 | |
179 | if(restart_cause()!= WDT_TIMEOUT) |
- | |
180 | { |
- | |
181 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
182 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
182 | setup_adc(ADC_CLOCK_DIV_2); |
183 | setup_adc(ADC_CLOCK_DIV_2); |
183 | setup_psp(PSP_DISABLED); |
184 | setup_psp(PSP_DISABLED); |
184 | setup_spi(SPI_SS_DISABLED); |
185 | setup_spi(SPI_SS_DISABLED); |
185 | setup_wdt(WDT_ON); |
186 | setup_wdt(WDT_OFF); |
186 | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
187 | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
187 | setup_timer_1(T1_DISABLED); |
188 | setup_timer_1(T1_DISABLED); |
188 | setup_timer_2(T2_DISABLED,0,1); |
189 | setup_timer_2(T2_DISABLED,0,1); |
189 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
190 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
190 | setup_ccp1(CCP_OFF); |
191 | setup_ccp1(CCP_OFF); |
191 | setup_comparator(NC_NC_NC_NC); |
192 | setup_comparator(NC_NC_NC_NC); |
192 | setup_vref(FALSE); |
193 | setup_vref(FALSE); |
193 | |
194 | |
194 | OFF(S105A); // Vsechno zhasni a zastav |
195 | OFF(S105A); // Vsechno zhasni a zastav |
195 | OFF(R110AU); |
196 | OFF(R110NU); |
196 | OFF(R110AD); |
197 | OFF(R110ND); |
197 | OFF(S104A); |
198 | OFF(S104A); |
198 | OFF(R104AU); |
199 | OFF(R104VU); |
199 | OFF(R104AD); |
200 | OFF(R104VD); |
200 | OFF(R104BU); |
201 | OFF(R104JU); |
201 | OFF(R104BD); |
202 | OFF(R104JD); |
202 | OFF(S103A); |
203 | OFF(S103J); |
203 | OFF(R103AU); |
204 | OFF(R103VU); |
204 | OFF(R103AD); |
205 | OFF(R103VD); |
205 | OFF(S106A); |
206 | OFF(S106A); |
206 | OFF(S107A); |
207 | OFF(S107A); |
207 | OFF(S109A); |
208 | OFF(S109A); |
208 | OFF(S101A); |
- | |
209 | OFF(S105D); |
209 | OFF(S105Z); |
210 | OFF(S102A); |
210 | OFF(S102A); |
211 | OFF(S110C); |
211 | OFF(S110N); |
212 | OFF(S108A); |
212 | OFF(S108A); |
213 | OFF(S201A); |
213 | OFF(S201A); |
214 | OFF(S110B); |
214 | OFF(S110J); |
215 | |
215 | |
216 | r103A=STOP; // Rolety jsou zastaveny |
216 | r103V=STOP; // Rolety jsou zastaveny |
217 | r110A=STOP; |
217 | r110N=STOP; |
218 | r104A=STOP; |
218 | r104V=STOP; |
219 | r104B=STOP; |
219 | r104J=STOP; |
- | 220 | |
|
- | 221 | output_high(LED1); // Indikace restartu |
|
- | 222 | delay_ms(100); |
|
- | 223 | output_low(LED1); |
|
- | 224 | delay_ms(30); |
|
- | 225 | output_high(LED1); |
|
- | 226 | restart_wdt(); |
|
- | 227 | delay_ms(100); |
|
- | 228 | output_low(LED1); |
|
- | 229 | delay_ms(30); |
|
- | 230 | output_high(LED1); |
|
- | 231 | restart_wdt(); |
|
220 | |
232 | |
221 | enable_interrupts(INT_TIMER0); |
233 | enable_interrupts(INT_TIMER0); |
222 | enable_interrupts(GLOBAL); |
234 | enable_interrupts(GLOBAL); |
223 | } |
- | |
224 | |
235 | |
225 | CREN=0; CREN=1; // Reinitialise USART |
236 | CREN=0; CREN=1; // Reinitialise USART |
226 | |
237 | |
227 | while(TRUE) |
238 | while(TRUE) |
228 | { |
239 | { |
- | 240 | |
|
229 | if(kbhit()) |
241 | if(kbhit()) // Chce po nas nekdo neco? |
230 | { |
242 | { |
231 | c=getc(); |
243 | buf[0]=getc(); |
232 | if(c=='S') |
244 | if((buf[0]=='S')||(buf[0]=='R')) // Jinym znakem nesmi zacinat prikaz |
233 | { |
245 | { |
- | 246 | int8 n=0; // Ukazatel do prijimaciho bufferu |
|
- | 247 | timer=RECEIVE; // Timeout pro prijem znaku |
|
- | 248 | |
|
234 | if(getc()=='1') |
249 | do |
235 | { |
250 | { |
- | 251 | if(kbhit()) // Je dalsi znak? |
|
- | 252 | { |
|
- | 253 | n++; |
|
236 | switch(getc()) |
254 | buf[n]=getc(); |
- | 255 | } |
|
- | 256 | } while ((buf[n]!='\r')&&(timer>0)&&(n<7)); |
|
- | 257 | |
|
- | 258 | if (timer==0) { CREN=0; CREN=1; } // Reinitialise USART |
|
- | 259 | |
|
- | 260 | output_toggle(LED1); // Ukonceni prijimani prikazu |
|
- | 261 | |
|
- | 262 | if((timer>0)) |
|
- | 263 | { |
|
- | 264 | |
|
- | 265 | if((buf[0]=='S')&&(n>=4)) // Zmena stavu svetla |
|
- | 266 | { |
|
- | 267 | if(buf[1]=='1') |
|
- | 268 | { |
|
- | 269 | switch(buf[2]) |
|
237 | { |
270 | { |
238 | case '1': |
- | |
239 | output_toggle(S101A); |
- | |
240 | break; |
- | |
241 | case '2': |
271 | case '2': |
242 | output_toggle(S102A); |
272 | output_toggle(S102A); |
243 | break; |
273 | break; |
244 | case '3': |
274 | case '3': |
245 | output_toggle(S103A); |
275 | output_toggle(S103J); |
246 | break; |
276 | break; |
247 | case '4': |
277 | case '4': |
248 | output_toggle(S104A); |
278 | output_toggle(S104A); |
249 | break; |
279 | break; |
250 | case '5': |
280 | case '5': |
251 | c=getc(); |
- | |
252 | if(c=='A') {output_toggle(S105A);} |
281 | if(buf[3]=='A') {output_toggle(S105A);} |
253 | if(c=='D') {output_toggle(S105D);} |
282 | if(buf[3]=='Z') {output_toggle(S105Z);} |
254 | break; |
283 | break; |
255 | case '6': |
284 | case '6': |
256 | output_toggle(S106A); |
285 | output_toggle(S106A); |
257 | break; |
286 | break; |
258 | case '7': |
287 | case '7': |
Line 263... | Line 292... | ||
263 | break; |
292 | break; |
264 | case '9': |
293 | case '9': |
265 | output_toggle(S109A); |
294 | output_toggle(S109A); |
266 | break; |
295 | break; |
267 | case 'a': |
296 | case 'a': |
268 | output_toggle(S110B); |
297 | output_toggle(S110J); |
269 | output_toggle(S110C); |
298 | output_toggle(S110N); |
270 | break; |
299 | break; |
271 | } |
300 | } |
272 | } |
301 | } |
273 | } |
302 | } |
274 | |
303 | |
275 | if(c=='R') |
304 | if((buf[0]=='R')&&(n>=5)) // Zmena stavu rolety |
276 | { |
305 | { |
277 | if(getc()=='1') |
306 | if(buf[1]=='1') |
278 | { |
307 | { |
279 | switch(getc()) |
308 | switch(buf[2]) |
280 | { |
309 | { |
281 | case '3': |
310 | case '3': |
282 | getc(); // A |
- | |
283 | if((getc()=='U')) {up(&r103A,&tr103A);} else {down(&r103A,&tr103A);} |
311 | if(buf[4]=='U') {up(&r103V,&tr103V);} else {down(&r103V,&tr103V);} |
284 | break; |
312 | break; |
285 | case '4': |
313 | case '4': |
286 | c=getc(); |
- | |
287 | if(c=='A') if((getc()=='U')) {up(&r104A,&tr104A);} else {down(&r104A,&tr104A);} |
314 | if(buf[3]=='V') if((buf[4]=='U')) {up(&r104V,&tr104V);} else {down(&r104V,&tr104V);} |
288 | if(c=='B') if((getc()=='U')) {up(&r104B,&tr104B);} else {down(&r104B,&tr104B);} |
315 | if(buf[3]=='J') if((buf[4]=='U')) {up(&r104J,&tr104J);} else {down(&r104J,&tr104J);} |
289 | break; |
316 | break; |
290 | case 'a': |
317 | case 'a': |
291 | getc(); // A |
- | |
292 | if((getc()=='U')) {up(&r110A,&tr110A);} else {down(&r110A,&tr110A);} |
318 | if((buf[4]=='U')) {up(&r110N,&tr110N);} else {down(&r110N,&tr110N);} |
293 | break; |
319 | break; |
294 | } |
320 | } |
295 | } |
321 | } |
296 | } |
322 | } |
297 | |
323 | |
298 | output_toggle(LED1); // Prijmuli jsme cely prikaz |
- | |
299 | } |
324 | } |
300 | else |
325 | } |
301 | { |
326 | } |
302 | run(103A); |
- | |
303 | run(104A); |
- | |
304 | run(104B); |
- | |
305 | |
327 | |
- | 328 | run(103V); // Rizeni rolet za behu |
|
- | 329 | run(104V); |
|
- | 330 | run(104J); |
|
- | 331 | |
|
306 | switch(r110A) |
332 | switch(r110N) // Zaluzie ma specielni rizeni |
307 | { |
333 | { |
308 | case STOP: |
334 | case STOP: |
309 | OFF(R110AU); |
335 | OFF(R110NU); |
310 | OFF(R110AD); |
336 | OFF(R110ND); |
311 | break; |
337 | break; |
312 | case GO_UP: |
338 | case GO_UP: |
313 | ON(R110AU); |
339 | ON(R110NU); |
314 | OFF(R110AD); |
340 | OFF(R110ND); |
315 | if(tr110A==0) {r110A=STOP;} |
341 | if(tr110N==0) {r110N=STOP;} |
316 | break; |
342 | break; |
317 | case GO_DOWN: |
343 | case GO_DOWN: |
318 | OFF(R110AU); |
344 | OFF(R110NU); |
319 | ON(R110AD); |
345 | ON(R110ND); |
320 | if(tr110A==0) {r110A=STOP;} |
346 | if(tr110N==0) {r110N=STOP;} |
321 | break; |
347 | break; |
322 | case REVERS_UP: |
348 | case REVERS_UP: |
323 | OFF(R110AU); |
349 | OFF(R110NU); |
324 | OFF(R110AD); |
350 | OFF(R110ND); |
325 | if(tr110A==0) {r110A=GO_UP; tr110A=GO_ZALUZIE;} |
351 | if(tr110N==0) {r110N=GO_UP; tr110N=GO_ZALUZIE;} |
326 | break; |
352 | break; |
327 | case REVERS_DOWN: |
353 | case REVERS_DOWN: |
328 | OFF(R110AU); |
354 | OFF(R110NU); |
329 | OFF(R110AD); |
355 | OFF(R110ND); |
330 | if(tr110A==0) {r110A=GO_DOWN; tr110A=GO_ZALUZIE;} |
356 | if(tr110N==0) {r110N=GO_DOWN; tr110N=GO_ZALUZIE;} |
331 | break; |
357 | break; |
332 | } |
358 | } |
333 | /* |
359 | /* |
334 | switch(r110A) |
360 | switch(r110A) |
335 | { |
361 | { |
Line 351... | Line 377... | ||
351 | } |
377 | } |
352 | */ |
378 | */ |
353 | restart_wdt(); |
379 | restart_wdt(); |
354 | } |
380 | } |
355 | } |
381 | } |
356 | } |
- |