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