1616 |
kakl |
1 |
/* DUM - provizorni ovladani svetel a rolet na hvezdarne */ |
|
|
2 |
#include "main.h" |
|
|
3 |
|
|
|
4 |
#CASE // Case sensitive compiler |
|
|
5 |
|
|
|
6 |
#define ZAKMIT 100 // Cas pro osetreni zakmitu v ms |
|
|
7 |
#define ZATAHNUTI 30000 // Cas potrebny na vysunuti rolety v ms |
|
|
8 |
#define REVERZ 300 // Cas pro reverzaci v ms |
|
|
9 |
|
|
|
10 |
#define S1_2 PIN_D0 // T1 Svetlo |
|
|
11 |
#define S1_5 PIN_D1 // T2 |
|
|
12 |
#define S2_7 PIN_D2 // T3 |
|
|
13 |
#define R2_7U PIN_D3 // T4 Roleta |
|
|
14 |
#define R2_7D PIN_D4 // T5 |
|
|
15 |
#define S2_9 PIN_D5 // T6 |
|
|
16 |
#define S2_3 PIN_D6 // T7 |
|
|
17 |
#define S2_1 PIN_D7 // T8 |
|
|
18 |
|
|
|
19 |
#define V1_2 !input(PIN_A0) // A Vypinac |
|
|
20 |
#define V2_1 !input(PIN_A1) // B |
|
|
21 |
#define V2_7 !input(PIN_A2) // C |
|
|
22 |
#define V2_7U !input(PIN_A3) // D Vypinac puleny |
|
|
23 |
#define V2_7D !input(PIN_A4) // E |
|
|
24 |
#define V2_6 !input(PIN_A5) // F |
|
|
25 |
#define V2_9 !input(PIN_E0) // G |
|
|
26 |
#define V2_3 !input(PIN_E1) // H |
|
|
27 |
|
|
|
28 |
#define ON(port) output_low(port); |
|
|
29 |
#define OFF(port) output_high(port); |
|
|
30 |
|
|
|
31 |
typedef enum {UP, DOWN, NOTHING} request; |
|
|
32 |
|
|
|
33 |
void main() |
|
|
34 |
{ |
|
|
35 |
int t1_2, t1_5; // Casovace |
|
|
36 |
int16 t2_7r; |
|
|
37 |
int16 t2_7; |
|
|
38 |
int vs1_2, vs1_2_old, vs1_5, vs1_5_old; // Vypinac schodistovy |
|
|
39 |
#bit vs1_2_0 = vs1_2.0 |
|
|
40 |
#bit vs1_2_1 = vs1_2.1 |
|
|
41 |
#bit vs1_2_2 = vs1_2.2 |
|
|
42 |
int v2_7, v2_7_old; |
|
|
43 |
#bit v2_7d = v2_7.0 |
|
|
44 |
#bit v2_7u = v2_7.1 |
|
|
45 |
#bit v2_7d_old = v2_7_old.0 |
|
|
46 |
#bit v2_7u_old = v2_7_old.1 |
|
|
47 |
request pozadavek2_7; |
|
|
48 |
|
|
|
49 |
setup_adc_ports(NO_ANALOGS); |
|
|
50 |
setup_adc(ADC_OFF); |
|
|
51 |
setup_psp(PSP_DISABLED); |
|
|
52 |
setup_spi(SPI_SS_DISABLED); |
|
|
53 |
setup_wdt(WDT_OFF); |
|
|
54 |
setup_timer_0(RTCC_INTERNAL); |
|
|
55 |
setup_timer_1(T1_DISABLED); |
|
|
56 |
setup_timer_2(T2_DISABLED,0,1); |
|
|
57 |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
|
|
58 |
setup_ccp1(CCP_OFF); |
|
|
59 |
setup_comparator(NC_NC_NC_NC); |
|
|
60 |
setup_vref(FALSE); |
|
|
61 |
|
|
|
62 |
printf("ahoj\r\n"); |
|
|
63 |
|
|
|
64 |
output_d(0xFF); // Vsechno zhasnout |
|
|
65 |
vs1_5 = V1_2; // Inicializace schodistaku |
|
|
66 |
vs1_5_old = vs1_5; |
|
|
67 |
vs1_2 = 0; |
|
|
68 |
vs1_2_1 = V2_1; |
|
|
69 |
vs1_2_2 = V2_6; |
|
|
70 |
vs1_2_old = vs1_2; |
|
|
71 |
v2_7 = 0; // Inicializace rolety |
|
|
72 |
v2_7d = V2_7D; |
|
|
73 |
v2_7u = V2_7U; |
|
|
74 |
v2_7_old = v2_7; |
|
|
75 |
t2_7 = ZATAHNUTI / 2; |
|
|
76 |
|
|
|
77 |
while(TRUE) |
|
|
78 |
{ |
|
|
79 |
vs1_2_1 = V2_1; // Precti stavy schodistaku a vypinacu rolet |
|
|
80 |
vs1_2_2 = V2_6; |
|
|
81 |
vs1_5 = V1_2; |
|
|
82 |
v2_7d = V2_7D; |
|
|
83 |
v2_7u = V2_7U; |
|
|
84 |
|
|
|
85 |
// Schodiste a kuchyn ---------------------------------------------------------- |
|
|
86 |
if ((vs1_5 != vs1_5_old) && (0 == t1_5)) |
|
|
87 |
{ |
|
|
88 |
vs1_5_old = vs1_5; |
|
|
89 |
t1_5 = ZAKMIT; |
|
|
90 |
if (!input_state(S1_5) && input_state(S1_2)) |
|
|
91 |
{ |
|
|
92 |
OFF(S1_5) |
|
|
93 |
} else |
|
|
94 |
if (input_state(S1_5) && input_state(S1_2)) |
|
|
95 |
{ |
|
|
96 |
ON(S1_5) |
|
|
97 |
ON(S1_2) |
|
|
98 |
ON(S2_1) |
|
|
99 |
} else |
|
|
100 |
if (!input_state(S1_5) && !input_state(S1_2)) |
|
|
101 |
{ |
|
|
102 |
OFF(S1_5) |
|
|
103 |
} else |
|
|
104 |
if (input_state(S1_5) && !input_state(S1_2)) |
|
|
105 |
{ |
|
|
106 |
OFF(S1_2) |
|
|
107 |
OFF(S2_1) |
|
|
108 |
} |
|
|
109 |
} |
|
|
110 |
|
|
|
111 |
if ((vs1_2_old != vs1_2) && (0 == t1_2)) // Schodiste |
|
|
112 |
{ |
|
|
113 |
vs1_2_old = vs1_2; |
|
|
114 |
t1_2 = ZAKMIT; |
|
|
115 |
output_toggle(S1_2); |
|
|
116 |
output_toggle(S2_1); |
|
|
117 |
} |
|
|
118 |
|
|
|
119 |
// Roleta klubovna ------------------------------------------------------------- |
|
|
120 |
if ((v2_7u_old != v2_7u) && (t2_7 > 0) && (0 == t2_7r)) // Pokud je pozadavek nahoru a nejsme nahore |
|
|
121 |
{ |
|
|
122 |
if (!input_state(R2_7U)) // Nejedeme zrovna nahoru? |
|
|
123 |
{ |
|
|
124 |
pozadavek2_7 = NOTHING; // Poznamenej pozadavek |
|
|
125 |
printf("pozadavek NOTHING\r\n"); |
|
|
126 |
} |
|
|
127 |
else |
|
|
128 |
{ |
|
|
129 |
pozadavek2_7 = UP; // Poznamenej pozadavek |
|
|
130 |
printf("pozadavek UP\r\n"); |
|
|
131 |
} |
|
|
132 |
OFF(R2_7D) // Zastav |
|
|
133 |
OFF(R2_7U) // Zastav |
|
|
134 |
t2_7r = REVERZ; // Cas pro zmenu pohybu |
|
|
135 |
v2_7_old = v2_7; // Poznamenej zmenu vypinace |
|
|
136 |
} |
|
|
137 |
|
|
|
138 |
if ((v2_7d_old != v2_7d) && (t2_7 < ZATAHNUTI) && (0 == t2_7r)) // Pokud je pozadavek dolu a nejsme dole |
|
|
139 |
{ |
|
|
140 |
if (!input_state(R2_7D)) // Nejedeme zrovna dolu? |
|
|
141 |
{ |
|
|
142 |
pozadavek2_7 = NOTHING; // Poznamenej pozadavek |
|
|
143 |
printf("pozadavek NOTHING\r\n"); |
|
|
144 |
} |
|
|
145 |
else |
|
|
146 |
{ |
|
|
147 |
pozadavek2_7 = DOWN; // Poznamenej pozadavek |
|
|
148 |
printf("pozadavek DOWN\r\n"); |
|
|
149 |
} |
|
|
150 |
OFF(R2_7D) // Zastav |
|
|
151 |
OFF(R2_7U) // Zastav |
|
|
152 |
t2_7r = REVERZ; // Cas pro zmenu pohybu |
|
|
153 |
v2_7_old = v2_7; // Poznamenej zmenu vypinace |
|
|
154 |
} |
|
|
155 |
|
|
|
156 |
if ((UP == pozadavek2_7) && (0 == t2_7r)) |
|
|
157 |
{ |
|
|
158 |
printf("UP\r\n"); |
|
|
159 |
ON(R2_7U) |
|
|
160 |
pozadavek2_7 = NOTHING; |
|
|
161 |
} |
|
|
162 |
|
|
|
163 |
if ((DOWN == pozadavek2_7) && (0 == t2_7r)) |
|
|
164 |
{ |
|
|
165 |
printf("DOWN\r\n"); |
|
|
166 |
ON(R2_7D) |
|
|
167 |
pozadavek2_7 = NOTHING; |
|
|
168 |
} |
|
|
169 |
|
|
|
170 |
if (t2_7 == 0) OFF(R2_7U); |
|
|
171 |
if (t2_7 == ZATAHNUTI) OFF(R2_7D); |
|
|
172 |
|
|
|
173 |
// Obycejna svetla ------------------------------------------------------------ |
|
|
174 |
if (V2_7) ON(S2_7) else OFF(S2_7) |
|
|
175 |
if (V2_3) ON(S2_3) else OFF(S2_3) |
|
|
176 |
if (V2_9) ON(S2_9) else OFF(S2_9) |
|
|
177 |
|
|
|
178 |
delay_ms(1); |
|
|
179 |
|
|
|
180 |
if (t1_2>0) t1_2--; |
|
|
181 |
if (t1_5>0) t1_5--; |
|
|
182 |
if (t2_7r>0) t2_7r--; |
|
|
183 |
if ((t2_7>0) && (!input_state(R2_7U))) t2_7--; |
|
|
184 |
if ((t2_7<ZATAHNUTI) && (!input_state(R2_7D))) t2_7++; |
|
|
185 |
} |
|
|
186 |
} |