Rev 1746 | Rev 1747 | ||
---|---|---|---|
1 | #include "main.h" |
1 | #include "main.h" |
2 | |
2 | |
3 | #case |
3 | #case |
4 | |
4 | |
- | 5 | #define REVERS 2 // 2*256 ms = 0,5 s |
|
- | 6 | #define GO 117 // 117*256 ms = 30 s |
|
- | 7 | #define GO_ZALUZIE 5 // 5*256 ms = 1,25 s |
|
- | 8 | |
|
5 | #define S105A PIN_A0 |
9 | #define S105A PIN_A0 |
6 | #define R105AU PIN_A1 |
10 | #define R110AU PIN_A1 |
7 | #define R105AD PIN_A2 |
11 | #define R110AD PIN_A2 |
8 | #define S104A PIN_A3 |
12 | #define S104A PIN_A3 |
9 | #define R104AU PIN_A4 |
13 | #define R104AU PIN_A4 |
10 | #define R104AD PIN_A5 |
14 | #define R104AD PIN_A5 |
11 | #define R104BU PIN_A6 |
15 | #define R104BU PIN_A6 |
12 | #define R104BD PIN_A7 |
16 | #define R104BD PIN_A7 |
13 | |
17 | |
14 | #define S103A PIN_B0 |
18 | #define S103A PIN_B0 |
15 | #define R103AU PIN_B1 |
19 | #define R103AU PIN_B1 |
16 | #define R103AD PIN_B2 |
20 | #define R103AD PIN_B2 |
17 | #define S106A PIN_B3 |
21 | #define S106A PIN_B3 |
18 | #define S107A PIN_B4 |
22 | #define S107A PIN_B4 |
19 | #define S109A PIN_B5 |
23 | #define S109A PIN_B5 |
20 | |
24 | |
21 | //#define OS101 PIN_C0 |
25 | //#define OS101 PIN_C0 |
22 | //#define OS105B PIN_C1 |
26 | //#define OS105B PIN_C1 |
23 | //#define OS105C PIN_C2 |
27 | //#define OS105C PIN_C2 |
24 | //#define PIN_C3 31763 |
28 | //#define PIN_C3 31763 |
25 | //#define PIN_C4 31764 |
29 | //#define PIN_C4 31764 |
26 | //#define PIN_C5 31765 |
30 | //#define PIN_C5 31765 |
27 | |
31 | |
28 | //#define PIN_C6 31766 //TX |
32 | //#define PIN_C6 31766 //TX |
29 | //#define PIN_C7 31767 //RX |
33 | //#define PIN_C7 31767 //RX |
30 | |
34 | |
31 | #define S101A PIN_D0 |
35 | #define S101A PIN_D0 |
32 | #define S105D PIN_D1 |
36 | #define S105D PIN_D1 |
33 | #define S102A PIN_D2 |
37 | #define S102A PIN_D2 |
34 | #define S110C PIN_D3 |
38 | #define S110C PIN_D3 |
35 | #define S108A PIN_D4 |
39 | #define S108A PIN_D4 |
36 | #define S201A PIN_D5 |
40 | #define S201A PIN_D5 |
37 | #define S110B PIN_D6 |
41 | #define S110B PIN_D6 |
38 | |
42 | |
39 | /* |
43 | /* |
40 | #define PIN_E0 31776 |
44 | #define PIN_E0 31776 |
41 | #define PIN_E1 31777 |
45 | #define PIN_E1 31777 |
42 | #define PIN_E2 31778 |
46 | #define PIN_E2 31778 |
43 | #define PIN_E3 31779 |
47 | #define PIN_E3 31779 |
44 | #define PIN_E4 31780 |
48 | #define PIN_E4 31780 |
45 | #define PIN_E5 31781 |
49 | #define PIN_E5 31781 |
46 | #define PIN_E6 31782 |
50 | #define PIN_E6 31782 |
47 | #define PIN_E7 31783 |
51 | #define PIN_E7 31783 |
48 | |
52 | |
49 | #define PIN_F0 31784 |
53 | #define PIN_F0 31784 |
50 | #define PIN_F1 31785 |
54 | #define PIN_F1 31785 |
51 | #define PIN_F2 31786 |
55 | #define PIN_F2 31786 |
52 | #define PIN_F3 31787 |
56 | #define PIN_F3 31787 |
53 | #define PIN_F4 31788 |
57 | #define PIN_F4 31788 |
54 | #define PIN_F5 31789 |
58 | #define PIN_F5 31789 |
55 | #define PIN_F6 31790 |
59 | #define PIN_F6 31790 |
56 | #define PIN_F7 31791 |
60 | #define PIN_F7 31791 |
57 | |
61 | |
58 | #define PIN_G0 31792 |
62 | #define PIN_G0 31792 |
59 | #define PIN_G1 31793 |
63 | #define PIN_G1 31793 |
60 | #define PIN_G2 31794 |
64 | #define PIN_G2 31794 |
61 | #define PIN_G3 31795 |
65 | #define PIN_G3 31795 |
62 | #define PIN_G4 31796 |
66 | #define PIN_G4 31796 |
63 | #define PIN_G5 31797 |
67 | #define PIN_G5 31797 |
64 | |
68 | |
65 | #define PIN_H0 31800 |
69 | #define PIN_H0 31800 |
66 | #define PIN_H1 31801 |
70 | #define PIN_H1 31801 |
67 | #define PIN_H2 31802 |
71 | #define PIN_H2 31802 |
68 | #define PIN_H3 31803 |
72 | #define PIN_H3 31803 |
69 | #define PIN_H4 31804 |
73 | #define PIN_H4 31804 |
70 | #define PIN_H5 31805 |
74 | #define PIN_H5 31805 |
71 | #define PIN_H6 31806 |
75 | #define PIN_H6 31806 |
72 | #define PIN_H7 31807 |
76 | #define PIN_H7 31807 |
73 | |
77 | |
74 | #define PIN_J0 31808 |
78 | #define PIN_J0 31808 |
75 | #define PIN_J1 31809 |
79 | #define PIN_J1 31809 |
76 | #define PIN_J2 31810 |
80 | #define PIN_J2 31810 |
77 | #define PIN_J3 31811 |
81 | #define PIN_J3 31811 |
78 | #define PIN_J4 31812 |
82 | #define PIN_J4 31812 |
79 | #define PIN_J5 31813 |
83 | #define PIN_J5 31813 |
80 | #define PIN_J6 31814 |
84 | #define PIN_J6 31814 |
81 | #define PIN_J7 31815 |
85 | #define PIN_J7 31815 |
82 | */ |
86 | */ |
83 | |
87 | |
- | 88 | #bit CREN = 0xFAB.4 // USART enable register |
|
- | 89 | |
|
84 | #define LED1 PIN_J7 |
90 | #define LED1 PIN_J7 |
85 | #define LED2 PIN_J6 |
91 | #define LED2 PIN_J6 |
86 | |
92 | |
87 | #define ON(port) output_low(port); |
93 | #define ON(port) output_low(port); |
88 | #define OFF(port) output_high(port); |
94 | #define OFF(port) output_high(port); |
89 | |
95 | |
90 | typedef enum {UP, DOWN, NOTHING} request; |
96 | typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
- | 97 | |
|
- | 98 | state r103A, r110A, r104A, r104B; // Stavy rolet |
|
- | 99 | int8 tr103A, tr110A, tr104A, tr104B; // Casovace rolet |
|
- | 100 | |
|
- | 101 | #int_TIMER0 |
|
- | 102 | void TIMER0_isr(void) |
|
- | 103 | { |
|
- | 104 | if(tr103A>0) tr103A--; |
|
- | 105 | if(tr110A>0) tr110A--; |
|
- | 106 | if(tr104A>0) tr104A--; |
|
- | 107 | if(tr104B>0) tr104B--; |
|
- | 108 | output_toggle(LED2); |
|
- | 109 | } |
|
- | 110 | |
|
- | 111 | void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
|
- | 112 | { |
|
- | 113 | switch (*status) |
|
- | 114 | { |
|
- | 115 | case STOP: |
|
- | 116 | case GO_DOWN: |
|
- | 117 | *status=REVERS_UP; |
|
- | 118 | *timer=REVERS; |
|
- | 119 | break; |
|
- | 120 | case REVERS_UP: |
|
- | 121 | case GO_UP: |
|
- | 122 | *status=STOP; |
|
- | 123 | *timer=0; |
|
- | 124 | break; |
|
- | 125 | } |
|
- | 126 | } |
|
- | 127 | |
|
- | 128 | void down(state *status, int8 *timer) // Zmena stavu rolety smer dolu |
|
- | 129 | { |
|
- | 130 | switch (*status) |
|
- | 131 | { |
|
- | 132 | case STOP: |
|
- | 133 | case GO_UP: |
|
- | 134 | *status=REVERS_DOWN; |
|
- | 135 | *timer=REVERS; |
|
- | 136 | break; |
|
- | 137 | case REVERS_DOWN: |
|
- | 138 | case GO_DOWN: |
|
- | 139 | *status=STOP; |
|
- | 140 | *timer=0; |
|
- | 141 | break; |
|
- | 142 | } |
|
- | 143 | } |
|
- | 144 | |
|
- | 145 | #define run(x) { \ |
|
- | 146 | switch(r##x) \ |
|
- | 147 | { \ |
|
- | 148 | case STOP: \ |
|
- | 149 | OFF(R##x##U); \ |
|
- | 150 | OFF(R##x##D); \ |
|
- | 151 | break; \ |
|
- | 152 | case GO_UP: \ |
|
- | 153 | ON(R##x##U); \ |
|
- | 154 | OFF(R##x##D); \ |
|
- | 155 | if(tr##x==0) {r##x=STOP;} \ |
|
- | 156 | break; \ |
|
- | 157 | case GO_DOWN: \ |
|
- | 158 | OFF(R##x##U); \ |
|
- | 159 | ON(R##x##D); \ |
|
- | 160 | if(tr##x==0) {r##x=STOP;} \ |
|
- | 161 | break; \ |
|
- | 162 | case REVERS_UP: \ |
|
- | 163 | OFF(R##x##U); \ |
|
- | 164 | OFF(R##x##D); \ |
|
- | 165 | if(tr##x==0) {r##x=GO_UP; tr##x=GO;} \ |
|
- | 166 | break; \ |
|
- | 167 | case REVERS_DOWN: \ |
|
- | 168 | OFF(R##x##U); \ |
|
- | 169 | OFF(R##x##D); \ |
|
- | 170 | if(tr##x==0) {r##x=GO_DOWN; tr##x=GO;} \ |
|
- | 171 | break; \ |
|
- | 172 | } \ |
|
- | 173 | } |
|
91 | |
174 | |
92 | void main() |
175 | void main() |
93 | { |
176 | { |
94 | char c; |
177 | char c; |
95 | |
178 | |
96 | if(restart_cause()!= WDT_TIMEOUT) |
179 | if(restart_cause()!= WDT_TIMEOUT) |
97 | { |
180 | { |
98 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
181 | setup_adc_ports(NO_ANALOGS|VSS_VDD); |
99 | setup_adc(ADC_CLOCK_DIV_2); |
182 | setup_adc(ADC_CLOCK_DIV_2); |
100 | setup_psp(PSP_DISABLED); |
183 | setup_psp(PSP_DISABLED); |
101 | setup_spi(SPI_SS_DISABLED); |
184 | setup_spi(SPI_SS_DISABLED); |
102 | setup_wdt(WDT_ON); |
185 | setup_wdt(WDT_ON); |
103 | setup_timer_0(RTCC_INTERNAL); |
186 | setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
104 | setup_timer_1(T1_DISABLED); |
187 | setup_timer_1(T1_DISABLED); |
105 | setup_timer_2(T2_DISABLED,0,1); |
188 | setup_timer_2(T2_DISABLED,0,1); |
106 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
189 | setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
107 | setup_ccp1(CCP_OFF); |
190 | setup_ccp1(CCP_OFF); |
108 | setup_comparator(NC_NC_NC_NC); |
191 | setup_comparator(NC_NC_NC_NC); |
109 | setup_vref(FALSE); |
192 | setup_vref(FALSE); |
110 | |
193 | |
111 | OFF(S105A); |
194 | OFF(S105A); // Vsechno zhasni a zastav |
112 | OFF(R105AU); |
195 | OFF(R110AU); |
113 | OFF(R105AD); |
196 | OFF(R110AD); |
114 | OFF(S104A); |
197 | OFF(S104A); |
115 | OFF(R104AU); |
198 | OFF(R104AU); |
116 | OFF(R104AD); |
199 | OFF(R104AD); |
117 | OFF(R104BU); |
200 | OFF(R104BU); |
118 | OFF(R104BD); |
201 | OFF(R104BD); |
119 | OFF(S103A); |
202 | OFF(S103A); |
120 | OFF(R103AU); |
203 | OFF(R103AU); |
121 | OFF(R103AD); |
204 | OFF(R103AD); |
122 | OFF(S106A); |
205 | OFF(S106A); |
123 | OFF(S107A); |
206 | OFF(S107A); |
124 | OFF(S109A); |
207 | OFF(S109A); |
125 | OFF(S101A); |
208 | OFF(S101A); |
126 | OFF(S105D); |
209 | OFF(S105D); |
127 | OFF(S102A); |
210 | OFF(S102A); |
128 | OFF(S110C); |
211 | OFF(S110C); |
129 | OFF(S108A); |
212 | OFF(S108A); |
130 | OFF(S201A); |
213 | OFF(S201A); |
131 | OFF(S110B); |
214 | OFF(S110B); |
- | 215 | |
|
- | 216 | r103A=STOP; // Rolety jsou zastaveny |
|
- | 217 | r110A=STOP; |
|
- | 218 | r104A=STOP; |
|
- | 219 | r104B=STOP; |
|
- | 220 | |
|
- | 221 | enable_interrupts(INT_TIMER0); |
|
- | 222 | enable_interrupts(GLOBAL); |
|
132 | } |
223 | } |
133 | |
224 | |
- | 225 | CREN=0; CREN=1; // Reinitialise USART |
|
- | 226 | |
|
134 | while(TRUE) |
227 | while(TRUE) |
135 | { |
228 | { |
136 | if(kbhit()) |
229 | if(kbhit()) |
137 | { |
230 | { |
138 | c=getc(); |
231 | c=getc(); |
139 | if(c=='S') |
232 | if(c=='S') |
140 | { |
233 | { |
141 | getc(); |
- | |
142 | switch(getc()) |
234 | if(getc()=='1') |
143 | { |
235 | { |
- | 236 | switch(getc()) |
|
- | 237 | { |
|
144 | case '1': |
238 | case '1': |
145 | output_toggle(S101A); |
239 | output_toggle(S101A); |
146 | break; |
240 | break; |
147 | case '2': |
241 | case '2': |
148 | output_toggle(S102A); |
242 | output_toggle(S102A); |
149 | break; |
243 | break; |
150 | case '3': |
244 | case '3': |
151 | output_toggle(S103A); |
245 | output_toggle(S103A); |
152 | break; |
246 | break; |
153 | case '4': |
247 | case '4': |
154 | output_toggle(S104A); |
248 | output_toggle(S104A); |
155 | break; |
249 | break; |
156 | case '5': |
250 | case '5': |
157 | c=getc(); |
251 | c=getc(); |
158 | if(c=='A') {output_toggle(S105A);} |
252 | if(c=='A') {output_toggle(S105A);} |
159 | if(c=='D') {output_toggle(S105D);} |
253 | if(c=='D') {output_toggle(S105D);} |
160 | break; |
254 | break; |
161 | case '6': |
255 | case '6': |
162 | output_toggle(S106A); |
256 | output_toggle(S106A); |
163 | break; |
257 | break; |
164 | case '7': |
258 | case '7': |
165 | output_toggle(S107A); |
259 | output_toggle(S107A); |
166 | break; |
260 | break; |
167 | case '8': |
261 | case '8': |
168 | output_toggle(S108A); |
262 | output_toggle(S108A); |
169 | break; |
263 | break; |
170 | case '9': |
264 | case '9': |
171 | output_toggle(S109A); |
265 | output_toggle(S109A); |
172 | break; |
266 | break; |
173 | case 'a': |
267 | case 'a': |
174 | output_toggle(S110B); |
268 | output_toggle(S110B); |
175 | output_toggle(S110C); |
269 | output_toggle(S110C); |
176 | break; |
270 | break; |
- | 271 | } |
|
177 | } |
272 | } |
178 | } |
273 | } |
179 | |
274 | |
180 | if(c=='R') |
275 | if(c=='R') |
181 | { |
276 | { |
182 | getc(); |
- | |
183 | switch(getc()) |
277 | if(getc()=='1') |
184 | { |
278 | { |
185 | case '3': |
279 | switch(getc()) |
186 | getc(); |
280 | { |
187 | c=getc(); |
281 | case '3': |
188 | if((c=='U')) {}; |
282 | getc(); // A |
- | 283 | if((getc()=='U')) {up(&r103A,&tr103A);} else {down(&r103A,&tr103A);} |
|
189 | break; |
284 | break; |
190 | case '4': |
285 | case '4': |
191 | c=getc(); |
286 | c=getc(); |
192 | if(c=='A') {}; |
287 | if(c=='A') if((getc()=='U')) {up(&r104A,&tr104A);} else {down(&r104A,&tr104A);} |
193 | if(c=='B') {}; |
288 | if(c=='B') if((getc()=='U')) {up(&r104B,&tr104B);} else {down(&r104B,&tr104B);} |
194 | break; |
289 | break; |
195 | case '5': |
290 | case 'a': |
196 | getc(); |
291 | getc(); // A |
- | 292 | if((getc()=='U')) {up(&r110A,&tr110A);} else {down(&r110A,&tr110A);} |
|
197 | getc(); |
293 | break; |
198 | break; |
294 | } |
199 | } |
295 | } |
200 | } |
296 | } |
- | 297 | |
|
201 | output_toggle(LED1); |
298 | output_toggle(LED1); // Prijmuli jsme cely prikaz |
202 | } |
299 | } |
203 | else |
300 | else |
204 | { |
301 | { |
- | 302 | run(103A); |
|
- | 303 | run(104A); |
|
- | 304 | run(104B); |
|
- | 305 | |
|
- | 306 | switch(r110A) |
|
- | 307 | { |
|
- | 308 | case STOP: |
|
- | 309 | OFF(R110AU); |
|
- | 310 | OFF(R110AD); |
|
- | 311 | break; |
|
- | 312 | case GO_UP: |
|
- | 313 | ON(R110AU); |
|
- | 314 | OFF(R110AD); |
|
- | 315 | if(tr110A==0) {r110A=STOP;} |
|
- | 316 | break; |
|
- | 317 | case GO_DOWN: |
|
- | 318 | OFF(R110AU); |
|
- | 319 | ON(R110AD); |
|
- | 320 | if(tr110A==0) {r110A=STOP;} |
|
- | 321 | break; |
|
- | 322 | case REVERS_UP: |
|
- | 323 | OFF(R110AU); |
|
- | 324 | OFF(R110AD); |
|
- | 325 | if(tr110A==0) {r110A=GO_UP; tr110A=GO_ZALUZIE;} |
|
- | 326 | break; |
|
- | 327 | case REVERS_DOWN: |
|
- | 328 | OFF(R110AU); |
|
- | 329 | OFF(R110AD); |
|
- | 330 | if(tr110A==0) {r110A=GO_DOWN; tr110A=GO_ZALUZIE;} |
|
- | 331 | break; |
|
- | 332 | } |
|
- | 333 | /* |
|
- | 334 | switch(r110A) |
|
- | 335 | { |
|
- | 336 | case GO_UP: |
|
- | 337 | printf("U"); |
|
- | 338 | break; |
|
- | 339 | case GO_DOWN: |
|
- | 340 | printf("D"); |
|
- | 341 | break; |
|
- | 342 | case REVERS_UP: |
|
- | 343 | printf("R"); |
|
- | 344 | break; |
|
- | 345 | case REVERS_DOWN: |
|
- | 346 | printf("E"); |
|
- | 347 | break; |
|
- | 348 | case STOP: |
|
- | 349 | printf("S"); |
|
- | 350 | break; |
|
- | 351 | } |
|
- | 352 | */ |
|
205 | restart_wdt(); |
353 | restart_wdt(); |
206 | } |
354 | } |
207 | } |
355 | } |
208 | } |
356 | } |