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