26,21 → 26,32 |
#use fast_io(D) |
#use fast_io(J) |
|
#define REVERS 3 // 3*256 ms = 0,75 s |
#define GO 117 // 117*256 ms = 30 s |
#define GO_ZALUZIE 6 // cca 1,5 s |
#define RECEIVE 10 // cca 2,6 s |
#define T_REVERS 5 // 5*256 ms = 1,25 s; pred prepnutim rele (zastaveni motoru a vybiti kondenzatoru) |
#define T_START 1 // 256 ms; po prepnuti rele do sepnuti triaku |
#define T_GO 117 // 117*256 ms = 30 s; max. beh rolety |
#define T_GO_ZALUZIE 6 // cca 1,5 s; beh zaluzie (pouze na preklopeni lamel) |
#define T_RECEIVE 10 // cca 2,6 s |
#define ZAKMIT 2000 // pocet pruchodu hlavni smyckou pred opetovnou detekci prepnuti vypinace |
|
#define OR110NU PIN_A0 // t1 Zaluzie koupelna dole |
#define OR110ND PIN_A1 // t2 |
#define OR207VU PIN_A2 // t3 Roleta klubovna |
#define OR207VD PIN_A3 // t4 |
#define OR103VU PIN_A4 // t5 Roleta loznice |
#define OR103VD PIN_A5 // t6 |
#define OR104JU PIN_A6 // t7 Roleta laborator jih |
#define OR104JD PIN_A7 // t8 |
#define OR106Z PIN_A0 // t1 Zaluzie trucovna zapad |
#define OR110N PIN_A1 // t2 Zaluzie koupelna dole sever |
#define OR104V PIN_A2 // t3 Roleta lab vychod |
#define OR104J PIN_A3 // t4 Roleta lab jih |
#define OR103V PIN_A4 // t5 Roleta loznice |
#define OR202J PIN_A5 // t6 Roleta Kaklik |
#define OR204Z PIN_A6 // t7 Roleta radiomistnost |
#define OR207V PIN_A7 // t8 Roleta klubovna |
|
#define OR208V PIN_F0 // t1 Roleta Zizala vychod |
#define OR208J PIN_F1 // t2 Roleta Zizala jih |
//??? #define OR107 PIN_F2 // t3 |
//??? #define OR107 PIN_F3 // t4 |
#define OR201Z PIN_F4 // t5 Roleta chodba nahore |
#define OR205N PIN_F5 // t6 Roleta puda |
//??? #define OR105 PIN_F6 // t7 Roleta kuchyn |
//#define O... PIN_F7 // t8 |
|
|
#define OS103J PIN_B0 // t1 Svetla loznice |
#define OS105Z PIN_B1 // t2 Svetlo kuchyn nad lavici |
#define OS110N PIN_B2 // t3 Svetlo koupelna dole zachod a sprhca |
64,17 → 75,8 |
#define OS202A PIN_E4 // t5 Svetlo Kaklik stred |
#define OS209A PIN_E5 // t6 Svetlo Zizala koupelna |
#define OS203A PIN_E6 // t7 Svetlo Kaklik koupelna |
//#define O... PIN_E7 // t8 |
#define RE PIN_E7 // t8 Rele pro rizeni smeru rolet |
|
#define OR104VU PIN_F0 // t1 Roleta laborator vychod |
#define OR104VD PIN_F1 // t2 |
#define OR202JU PIN_F2 // t3 Roleta Kaklik |
#define OR202JD PIN_F3 // t4 |
#define OR204ZU PIN_F4 // t5 Roleta radiomistnost |
#define OR204ZD PIN_F5 // t6 |
//#define O... PIN_F6 // t7 |
//#define O... PIN_F7 // t8 |
|
//#define I.... input(PIN_D0) // A |
#define IS201AZ input(PIN_D1) // B Vypinac chodba 2.n.p. zapad u Kaklika |
#define IS207AJ input(PIN_D2) // C Vypinac klubovna |
116,26 → 118,57 |
#define ON(port) output_low(port); |
#define OFF(port) output_high(port); |
|
typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
typedef enum {RUN, STOP} roleta_state; |
roleta_state rol[18]; // Stavy rolet |
#define R103V 0 |
#define R110N 1 |
#define R104V 2 |
#define R104J 3 |
#define R207V 4 |
#define R202J 5 |
#define R204Z 6 |
|
state r103V, r110N, r104V, r104J, r207V, r202J, r204Z; // Stavy rolet |
int8 tr103V, tr110N, tr104V, tr104J, tr207V, tr202J, tr204Z; // Casovace rolet |
typedef enum {UP, DOWN, REVERS_UP, REVERS_DOWN, RUN_UP, RUN_DOWN} relay_state; |
relay_state relay; // Stavy rele |
|
int8 timer_run; // Bezpecnostni casovac behu rolety |
int8 timer_run_zaluzie; // Casovac zaluzie na preklopeni lamel |
int8 timer_revers; // Prodleva na vybiti kondenzatoru pa zastaveni rolety pred prepnutim rele |
int8 timer_start; // Prodleva na prepnuti rele pred startem rolety |
int8 timer; // Casovac komunikace |
|
#int_TIMER0 |
void TIMER0_isr(void) |
{ |
if(tr103V>0) tr103V--; |
if(tr110N>0) tr110N--; |
if(tr104V>0) tr104V--; |
if(tr104J>0) tr104J--; |
if(tr207V>0) tr207V--; |
if(tr202J>0) tr202J--; |
if(tr204Z>0) tr204Z--; |
if(timer>0) timer--; |
if(timer_run>0) timer_run--; |
if(timer_revers>0) timer_revers--; |
if(timer_start>0) timer_start--; |
if(timer_run_zaluzie>0) timer_run_zaluzie--; |
output_toggle(LED2); |
} |
|
void stop_all() // Zastav vsechny rolety |
{ |
int8 n; |
|
for(n=0; n<18; n++) rol[n]=STOP; |
output_a(0xFF); |
output_f(0xFF); |
} |
|
void run_all() // Spust rolety |
{ |
if (rol[R103V]==RUN) ON(OR103V); |
if (rol[R110N]==RUN) ON(OR110N); |
if (rol[R104V]==RUN) ON(OR104V); |
if (rol[R104J]==RUN) ON(OR104J); |
if (rol[R207V]==RUN) ON(OR207V); |
if (rol[R202J]==RUN) ON(OR202J); |
if (rol[R204Z]==RUN) ON(OR204Z); |
} |
|
/* |
void up(state *status, int8 *timer) // Zmena stavu rolety smer nahoru |
{ |
switch (*status) |
199,6 → 232,7 |
break; \ |
} \ |
} |
*/ |
|
void main() |
{ |
229,22 → 263,17 |
output_b(0xFF); |
output_f(0xFF); |
output_e(0xFF); |
stop_all(); |
|
r103V=STOP; // Rolety jsou zastaveny |
r110N=STOP; |
r104V=STOP; |
r104J=STOP; |
r207V=STOP; |
r202J=STOP; |
r204Z=STOP; |
tr103V=0; |
tr110N=0; |
tr104V=0; |
tr104J=0; |
tr207V=0; |
tr202J=0; |
tr204Z=0; |
timer_run=0; // Zastav vsechny casovace |
timer=0; |
timer_revers=0; |
timer_start=0; |
timer_run_zaluzie=0; |
zakmity=0; |
|
relay=RUN_UP; // Rele je na zacatku vypnuto |
|
{ |
int n; |
|
288,7 → 317,7 |
if((buf[0]=='S')||(buf[0]=='R')) // Jinym znakem nesmi zacinat prikaz |
{ |
int8 n=0; // Ukazatel do prijimaciho bufferu |
timer=RECEIVE; // Timeout pro prijem znaku |
timer=T_RECEIVE; // Timeout pro prijem znaku |
|
do |
{ |
352,14 → 381,14 |
switch(buf[2]) |
{ |
case '3': |
if(buf[4]=='U') {up(&r103V,&tr103V);} else {down(&r103V,&tr103V);} |
//!!! if(buf[4]=='U') {up(&r103V,&tr103V);} else {down(&r103V,&tr103V);} |
break; |
case '4': |
if(buf[3]=='V') if((buf[4]=='U')) {up(&r104V,&tr104V);} else {down(&r104V,&tr104V);} |
if(buf[3]=='J') if((buf[4]=='U')) {up(&r104J,&tr104J);} else {down(&r104J,&tr104J);} |
//!!! if(buf[3]=='V') if((buf[4]=='U')) |
//!!! if(buf[3]=='J') if((buf[4]=='U')) {up(&r104J,&tr104J);} else {down(&r104J,&tr104J);} |
break; |
case 'a': |
if((buf[4]=='U')) {up(&r110N,&tr110N);} else {down(&r110N,&tr110N);} |
//!!! if((buf[4]=='U')) {up(&r110N,&tr110N);} else {down(&r110N,&tr110N);} |
break; |
} |
} |
369,41 → 398,8 |
} |
} |
|
run(103V); // Rizeni rolet za behu |
// run(104V); |
run(104J); |
run(207V); |
run(202J); |
run(204Z); |
//!!! switch(r110N) // Zaluzie ma specielni rizeni |
|
switch(r110N) // Zaluzie ma specielni rizeni |
{ |
case STOP: |
OFF(OR110NU); |
OFF(OR110ND); |
break; |
case GO_UP: |
OFF(OR110ND); |
ON(OR110NU); |
if(tr110N==0) {r110N=STOP;} |
break; |
case GO_DOWN: |
OFF(OR110NU); |
ON(OR110ND); |
if(tr110N==0) {r110N=STOP;} |
break; |
case REVERS_UP: |
OFF(OR110NU); |
OFF(OR110ND); |
if(tr110N==0) {r110N=GO_UP; tr110N=GO_ZALUZIE;} // Nahoru pouze kratce na otevreni zaluzie |
break; |
case REVERS_DOWN: |
OFF(OR110NU); |
OFF(OR110ND); |
if(tr110N==0) {r110N=GO_DOWN; tr110N=GO_ZALUZIE;} // Dolu take kratce pouze na zaklopeni zaluzie |
break; |
} |
|
// mistni vypinace z 2. n.p. |
if (0==zakmity) |
{ |
416,13 → 412,119 |
if(s204AJ!=IS204AJ) {s204AJ=IS204AJ; output_toggle(OS204A); zakmity=ZAKMIT;} |
if(s202AN!=IS202AN) {s202AN=IS202AN; output_toggle(OS202A); zakmity=ZAKMIT;} |
|
if(r207VU!=IR207VU) {r207VU=IR207VU; up(&r207V,&tr207V); zakmity=ZAKMIT;} |
if(r207VD!=IR207VD) {r207VD=IR207VD; down(&r207V,&tr207V); zakmity=ZAKMIT;} |
if(r202NU!=IR202NU) {r202NU=IR202NU; up(&r202J,&tr202J); zakmity=ZAKMIT;} |
if(r202ND!=IR202ND) {r202ND=IR202ND; down(&r202J,&tr202J); zakmity=ZAKMIT;} |
if(r204ZU!=IR204ZU) {r204ZU=IR204ZU; up(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
if(r204ZD!=IR204ZD) {r204ZD=IR204ZD; down(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
if(r207VU!=IR207VU) // Zmenil se stav vypinace |
{ |
r207VU=IR207VU; // Poznamenej soucasny stav vypinace |
|
if (rol[R207V]==RUN) |
{ |
rol[R207V]=STOP; // Roleta jela, tak zastav |
OFF(OR207V); |
} |
else |
{ |
if ((relay==DOWN)||(relay==RUN_DOWN)) // Rele je prepnuto na druhou stranu! |
{ |
relay=REVERS_UP; // Reverzuj |
timer_revers=T_REVERS; |
stop_all(); // Vsechno zastav |
} |
if (relay==RUN_UP) |
{ |
ON(OR207V); // Jede se spravnym smerem, tak jenom pust roletu |
} |
rol[R104V]=RUN; // Poznamenej, ze se jede, a natahni bezpecnostni casovac |
timer_run=T_GO; |
} |
zakmity=ZAKMIT; |
} |
if(r207VD!=IR207VD) |
{ |
r207VD=IR207VD; |
|
if (rol[R207V]==RUN) |
{ |
rol[R207V]=STOP; |
OFF(OR207V); |
} |
else |
{ |
if ((relay==UP)||(relay==RUN_UP)) |
{ |
relay=REVERS_DOWN; |
timer_revers=T_REVERS; |
stop_all(); |
} |
if (relay==RUN_DOWN) |
{ |
ON(OR207V); |
} |
rol[R104V]=RUN; |
timer_run=T_GO; |
} |
zakmity=ZAKMIT; |
} |
|
//!!! if(r202NU!=IR202NU) {r202NU=IR202NU; up(&r202J,&tr202J); zakmity=ZAKMIT;} |
//!!! if(r202ND!=IR202ND) {r202ND=IR202ND; down(&r202J,&tr202J); zakmity=ZAKMIT;} |
//!!! if(r204ZU!=IR204ZU) {r204ZU=IR204ZU; up(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
//!!! if(r204ZD!=IR204ZD) {r204ZD=IR204ZD; down(&r204Z,&tr204Z); zakmity=ZAKMIT;} |
} |
else zakmity--; |
} |
|
switch (relay) |
{ |
case UP: |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
{ |
relay=RUN_UP; // Zmen stav na "jede se" |
run_all(); // Sepni triaky u rolet, ktere maji jet |
timer_run=T_GO; // Natahni bezpecnostni casovac |
} |
break; |
|
case DOWN: |
if (timer_start==0) // Rele prepnuto, muzeme sepnout triaky |
{ |
relay=RUN_DOWN; // Zmen stav na "jede se" |
run_all(); // Sepni triaky u rolet, ktere maji jet |
timer_run=T_GO; // Natahni bezpecnostni casovac |
} |
break; |
|
case RUN_UP: |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
{ |
stop_all(); // Vsechno zastav |
} |
break; |
|
case RUN_DOWN: |
if (timer_run==0) // Vyprsel bezpecnostni casovac |
{ |
relay=REVERS_UP; // Vsechno zastav a reverzuj pro prepnuti rele do klidove polohy bez energizace civky |
stop_all(); |
timer_revers=T_REVERS; |
} |
break; |
|
case REVERS_UP: |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
{ |
relay=UP; // Prepni rele |
OFF(RE); |
timer_start=T_START; // Pockej na prepnuti rele |
} |
break; |
|
case REVERS_DOWN: |
if (timer_revers==0) // Uz se snad vybil kondenzator, muzeme reverzovat |
{ |
relay=DOWN; // Prepni rele |
ON(RE); |
timer_start=T_START; // Pockej na prepnuti rele |
} |
break; |
} |
} |