0,0 → 1,186 |
/* DUM - provizorni ovladani svetel a rolet na hvezdarne */ |
#include "main.h" |
|
#CASE // Case sensitive compiler |
|
#define ZAKMIT 100 // Cas pro osetreni zakmitu v ms |
#define ZATAHNUTI 30000 // Cas potrebny na vysunuti rolety v ms |
#define REVERZ 300 // Cas pro reverzaci v ms |
|
#define S1_2 PIN_D0 // T1 Svetlo |
#define S1_5 PIN_D1 // T2 |
#define S2_7 PIN_D2 // T3 |
#define R2_7U PIN_D3 // T4 Roleta |
#define R2_7D PIN_D4 // T5 |
#define S2_9 PIN_D5 // T6 |
#define S2_3 PIN_D6 // T7 |
#define S2_1 PIN_D7 // T8 |
|
#define V1_2 !input(PIN_A0) // A Vypinac |
#define V2_1 !input(PIN_A1) // B |
#define V2_7 !input(PIN_A2) // C |
#define V2_7U !input(PIN_A3) // D Vypinac puleny |
#define V2_7D !input(PIN_A4) // E |
#define V2_6 !input(PIN_A5) // F |
#define V2_9 !input(PIN_E0) // G |
#define V2_3 !input(PIN_E1) // H |
|
#define ON(port) output_low(port); |
#define OFF(port) output_high(port); |
|
typedef enum {UP, DOWN, NOTHING} request; |
|
void main() |
{ |
int t1_2, t1_5; // Casovace |
int16 t2_7r; |
int16 t2_7; |
int vs1_2, vs1_2_old, vs1_5, vs1_5_old; // Vypinac schodistovy |
#bit vs1_2_0 = vs1_2.0 |
#bit vs1_2_1 = vs1_2.1 |
#bit vs1_2_2 = vs1_2.2 |
int v2_7, v2_7_old; |
#bit v2_7d = v2_7.0 |
#bit v2_7u = v2_7.1 |
#bit v2_7d_old = v2_7_old.0 |
#bit v2_7u_old = v2_7_old.1 |
request pozadavek2_7; |
|
setup_adc_ports(NO_ANALOGS); |
setup_adc(ADC_OFF); |
setup_psp(PSP_DISABLED); |
setup_spi(SPI_SS_DISABLED); |
setup_wdt(WDT_OFF); |
setup_timer_0(RTCC_INTERNAL); |
setup_timer_1(T1_DISABLED); |
setup_timer_2(T2_DISABLED,0,1); |
setup_timer_3(T3_DISABLED|T3_DIV_BY_1); |
setup_ccp1(CCP_OFF); |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
|
printf("ahoj\r\n"); |
|
output_d(0xFF); // Vsechno zhasnout |
vs1_5 = V1_2; // Inicializace schodistaku |
vs1_5_old = vs1_5; |
vs1_2 = 0; |
vs1_2_1 = V2_1; |
vs1_2_2 = V2_6; |
vs1_2_old = vs1_2; |
v2_7 = 0; // Inicializace rolety |
v2_7d = V2_7D; |
v2_7u = V2_7U; |
v2_7_old = v2_7; |
t2_7 = ZATAHNUTI / 2; |
|
while(TRUE) |
{ |
vs1_2_1 = V2_1; // Precti stavy schodistaku a vypinacu rolet |
vs1_2_2 = V2_6; |
vs1_5 = V1_2; |
v2_7d = V2_7D; |
v2_7u = V2_7U; |
|
// Schodiste a kuchyn ---------------------------------------------------------- |
if ((vs1_5 != vs1_5_old) && (0 == t1_5)) |
{ |
vs1_5_old = vs1_5; |
t1_5 = ZAKMIT; |
if (!input_state(S1_5) && input_state(S1_2)) |
{ |
OFF(S1_5) |
} else |
if (input_state(S1_5) && input_state(S1_2)) |
{ |
ON(S1_5) |
ON(S1_2) |
ON(S2_1) |
} else |
if (!input_state(S1_5) && !input_state(S1_2)) |
{ |
OFF(S1_5) |
} else |
if (input_state(S1_5) && !input_state(S1_2)) |
{ |
OFF(S1_2) |
OFF(S2_1) |
} |
} |
|
if ((vs1_2_old != vs1_2) && (0 == t1_2)) // Schodiste |
{ |
vs1_2_old = vs1_2; |
t1_2 = ZAKMIT; |
output_toggle(S1_2); |
output_toggle(S2_1); |
} |
|
// Roleta klubovna ------------------------------------------------------------- |
if ((v2_7u_old != v2_7u) && (t2_7 > 0) && (0 == t2_7r)) // Pokud je pozadavek nahoru a nejsme nahore |
{ |
if (!input_state(R2_7U)) // Nejedeme zrovna nahoru? |
{ |
pozadavek2_7 = NOTHING; // Poznamenej pozadavek |
printf("pozadavek NOTHING\r\n"); |
} |
else |
{ |
pozadavek2_7 = UP; // Poznamenej pozadavek |
printf("pozadavek UP\r\n"); |
} |
OFF(R2_7D) // Zastav |
OFF(R2_7U) // Zastav |
t2_7r = REVERZ; // Cas pro zmenu pohybu |
v2_7_old = v2_7; // Poznamenej zmenu vypinace |
} |
|
if ((v2_7d_old != v2_7d) && (t2_7 < ZATAHNUTI) && (0 == t2_7r)) // Pokud je pozadavek dolu a nejsme dole |
{ |
if (!input_state(R2_7D)) // Nejedeme zrovna dolu? |
{ |
pozadavek2_7 = NOTHING; // Poznamenej pozadavek |
printf("pozadavek NOTHING\r\n"); |
} |
else |
{ |
pozadavek2_7 = DOWN; // Poznamenej pozadavek |
printf("pozadavek DOWN\r\n"); |
} |
OFF(R2_7D) // Zastav |
OFF(R2_7U) // Zastav |
t2_7r = REVERZ; // Cas pro zmenu pohybu |
v2_7_old = v2_7; // Poznamenej zmenu vypinace |
} |
|
if ((UP == pozadavek2_7) && (0 == t2_7r)) |
{ |
printf("UP\r\n"); |
ON(R2_7U) |
pozadavek2_7 = NOTHING; |
} |
|
if ((DOWN == pozadavek2_7) && (0 == t2_7r)) |
{ |
printf("DOWN\r\n"); |
ON(R2_7D) |
pozadavek2_7 = NOTHING; |
} |
|
if (t2_7 == 0) OFF(R2_7U); |
if (t2_7 == ZATAHNUTI) OFF(R2_7D); |
|
// Obycejna svetla ------------------------------------------------------------ |
if (V2_7) ON(S2_7) else OFF(S2_7) |
if (V2_3) ON(S2_3) else OFF(S2_3) |
if (V2_9) ON(S2_9) else OFF(S2_9) |
|
delay_ms(1); |
|
if (t1_2>0) t1_2--; |
if (t1_5>0) t1_5--; |
if (t2_7r>0) t2_7r--; |
if ((t2_7>0) && (!input_state(R2_7U))) t2_7--; |
if ((t2_7<ZATAHNUTI) && (!input_state(R2_7D))) t2_7++; |
} |
} |