1,3 → 1,13 |
/* |
Ovladani domu rozvadec 2. n.p. |
|
Syntaxe prikazu: |
|
<Roleta/Svetlo><#patro><#mistnost><Nord/Jih/Vychod/Zapad/A/B><Up/Down> |
R2aNU - roleta, 2. n.p., mistnost 10, sever, nahoru |
S12A - svetlo, 1. n.p., mistnost 2, prostredni |
|
*/ |
#include "main.h" |
|
#case |
7,89 → 17,72 |
#define GO_ZALUZIE 6 // cca 1,5 s |
#define RECEIVE 10 // cca 2,6 s |
|
#define S105A PIN_A0 |
#define R110NU PIN_A1 |
#define R110ND PIN_A2 |
#define S104A PIN_A3 |
#define R104VU PIN_A4 |
#define R104VD PIN_A5 |
#define R104JU PIN_A6 |
#define R104JD PIN_A7 |
#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 OR104VU PIN_A4 // Roleta laborator vychod |
//#define OR104VD PIN_A5 |
#define OR104JU PIN_A6 // t7 Roleta laborator jih |
#define OR104JD PIN_A7 // t8 |
|
#define S103J PIN_B0 |
#define R103VU PIN_B1 |
#define R103VD PIN_B2 |
#define S106A PIN_B3 |
#define S107A PIN_B4 |
#define S109A PIN_B5 |
#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 |
#define OS106A PIN_B3 // t4 Svetlo trucovna stred |
#define OS107A PIN_B4 // t5 Svetlo satna |
#define OS109A PIN_B5 // t6 Svetlo technologicka mistnost |
//#define OS110J PIN_B6 // t7 Svetlo koupelna dole sprcha |
//#define O... PIN_B7 // t8 |
|
//#define OS101 PIN_C0 |
//#define OS105B PIN_C1 |
//#define OS105C PIN_C2 |
//#define PIN_C3 31763 |
//#define PIN_C4 31764 |
//#define PIN_C5 31765 |
|
//#define PIN_C6 31766 //TX |
//#define PIN_C7 31767 //RX |
|
//#define S101A PIN_F0 |
#define S105Z PIN_F1 |
#define S102A PIN_F2 |
#define S110N PIN_F3 |
#define S108A PIN_F4 |
#define S201A PIN_F5 |
#define S110J PIN_F6 |
//#define O... PIN_F0 // t1 |
//#define O... PIN_F1 // t2 |
//#define O... PIN_F2 // t3 |
//#define O... PIN_F3 // t4 |
//#define O... PIN_F4 // t5 |
//#define O... PIN_F5 // t6 |
//#define O... PIN_F6 // t7 |
//#define O... PIN_F7 // t8 |
|
/* |
#define PIN_E0 31776 |
#define PIN_E1 31777 |
#define PIN_E2 31778 |
#define PIN_E3 31779 |
#define PIN_E4 31780 |
#define PIN_E5 31781 |
#define PIN_E6 31782 |
#define PIN_E7 31783 |
//#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 |
#define IR207VU input(PIN_D3) // D Vypinac roleta klubovna nahoru |
#define IR207VD input(PIN_D4) // E Vypinac roleta klubovna dolu |
#define IS201AV input(PIN_D5) // F Vypinac chodba 2.n.p. vychod |
#define IS209AJ input(PIN_D6) // G Vypinac koupelna Zizala |
#define IS203AJ input(PIN_D7) // H Vypinac koupelna Kaklik |
|
#define PIN_F0 31784 |
#define PIN_F1 31785 |
#define PIN_F2 31786 |
#define PIN_F3 31787 |
#define PIN_F4 31788 |
#define PIN_F5 31789 |
#define PIN_F6 31790 |
#define PIN_F7 31791 |
#define OS102A PIN_E0 // t1 Svetlo chodba |
#define OS105A PIN_E1 //* t2 Svetlo kuchyne stred |
#define OS207A PIN_E2 // t3 Svetlo klubovna |
#define OS104A PIN_E3 //* t4 Svetlo laborator |
//#define O... PIN_E4 // t5 |
#define OS209A PIN_E5 // t6 Svetlo Zizala koupelna |
#define OS203A PIN_E6 // t7 Svetlo Kaklik koupelna |
//#define O... PIN_E7 // t8 |
|
#define PIN_G0 31792 |
#define PIN_G1 31793 |
#define PIN_G2 31794 |
#define PIN_G3 31795 |
#define PIN_G4 31796 |
#define PIN_G5 31797 |
int1 s201AV; |
int1 s201AZ; |
int1 s207AJ; |
int1 s203AJ; |
int1 s209AJ; |
int1 r207VU; |
int1 r207VD; |
|
#define PIN_H0 31800 |
#define PIN_H1 31801 |
#define PIN_H2 31802 |
#define PIN_H3 31803 |
#define PIN_H4 31804 |
#define PIN_H5 31805 |
#define PIN_H6 31806 |
#define PIN_H7 31807 |
|
#define PIN_J0 31808 |
#define PIN_J1 31809 |
#define PIN_J2 31810 |
#define PIN_J3 31811 |
#define PIN_J4 31812 |
#define PIN_J5 31813 |
#define PIN_J6 31814 |
#define PIN_J7 31815 |
*/ |
|
#bit CREN = 0xFAB.4 // USART enable register |
|
#define LED1 PIN_J7 |
#define LED2 PIN_J6 |
#define LED1 PIN_C0 |
#define LED2 PIN_C1 |
|
#define ON(port) output_low(port); |
#define OFF(port) output_high(port); |
96,8 → 89,8 |
|
typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
|
state r103V, r110N, r104V, r104J; // Stavy rolet |
int8 tr103V, tr110N, tr104V, tr104J; // Casovace rolet |
state r103V, r110N, r104V, r104J, r207V; // Stavy rolet |
int8 tr103V, tr110N, tr104V, tr104J, tr207V; // Casovace rolet |
int8 timer; // Casovac komunikace |
|
#int_TIMER0 |
107,6 → 100,7 |
if(tr110N>0) tr110N--; |
if(tr104V>0) tr104V--; |
if(tr104J>0) tr104J--; |
if(tr207V>0) tr207V--; |
if(timer>0) timer--; |
output_toggle(LED2); |
} |
149,27 → 143,27 |
switch(r##x) \ |
{ \ |
case STOP: \ |
OFF(R##x##U); \ |
OFF(R##x##D); \ |
OFF(OR##x##U); \ |
OFF(OR##x##D); \ |
break; \ |
case GO_UP: \ |
ON(R##x##U); \ |
OFF(R##x##D); \ |
OFF(OR##x##D); \ |
ON(OR##x##U); \ |
if(tr##x==0) {r##x=STOP;} \ |
break; \ |
case GO_DOWN: \ |
OFF(R##x##U); \ |
ON(R##x##D); \ |
OFF(OR##x##U); \ |
ON(OR##x##D); \ |
if(tr##x==0) {r##x=STOP;} \ |
break; \ |
case REVERS_UP: \ |
OFF(R##x##U); \ |
OFF(R##x##D); \ |
OFF(OR##x##U); \ |
OFF(OR##x##D); \ |
if(tr##x==0) {r##x=GO_UP; tr##x=GO;} \ |
break; \ |
case REVERS_DOWN: \ |
OFF(R##x##U); \ |
OFF(R##x##D); \ |
OFF(OR##x##U); \ |
OFF(OR##x##D); \ |
if(tr##x==0) {r##x=GO_DOWN; tr##x=GO;} \ |
break; \ |
} \ |
192,37 → 186,23 |
setup_comparator(NC_NC_NC_NC); |
setup_vref(FALSE); |
|
OFF(S105A); // Vsechno zhasni a zastav |
OFF(R110NU); |
OFF(R110ND); |
OFF(S104A); |
OFF(R104VU); |
OFF(R104VD); |
OFF(R104JU); |
OFF(R104JD); |
OFF(S103J); |
OFF(R103VU); |
OFF(R103VD); |
OFF(S106A); |
OFF(S107A); |
OFF(S109A); |
OFF(S105Z); |
OFF(S102A); |
OFF(S110N); |
OFF(S108A); |
OFF(S201A); |
OFF(S110J); |
output_a(0xFF); // Vsechno zhasni a zastav |
output_b(0xFF); |
output_f(0xFF); |
output_e(0xFF); |
|
r103V=STOP; // Rolety jsou zastaveny |
r110N=STOP; |
r104V=STOP; |
r104J=STOP; |
r207V=STOP; |
tr103V=0; |
tr110N=0; |
tr104V=0; |
tr104J=0; |
tr207V=0; |
|
output_high(LED1); // Indikace restartu |
output_high(LED1); // Indikace restartu (pockame na nabiti kondenzatoru ve vstupnich obvodech) |
delay_ms(100); |
output_low(LED1); |
delay_ms(30); |
234,6 → 214,14 |
output_high(LED1); |
restart_wdt(); |
|
s201AV=IS201AV; // Precteme vychozi stav vypinacu |
s201AZ=IS201AZ; |
s207AJ=IS207AJ; |
s203AJ=IS203AJ; |
s209AJ=IS209AJ; |
r207VU=IR207VU; |
r207VD=IR207VD; |
|
enable_interrupts(INT_TIMER0); |
enable_interrupts(GLOBAL); |
|
273,33 → 261,33 |
switch(buf[2]) |
{ |
case '2': |
output_toggle(S102A); |
output_toggle(OS102A); |
break; |
case '3': |
output_toggle(S103J); |
output_toggle(OS103J); |
break; |
case '4': |
output_toggle(S104A); |
output_toggle(OS104A); |
break; |
case '5': |
if(buf[3]=='A') {output_toggle(S105A);} |
if(buf[3]=='Z') {output_toggle(S105Z);} |
if(buf[3]=='A') {output_toggle(OS105A);} |
if(buf[3]=='Z') {output_toggle(OS105Z);} |
break; |
case '6': |
output_toggle(S106A); |
output_toggle(OS106A); |
break; |
case '7': |
output_toggle(S107A); |
output_toggle(OS107A); |
break; |
case '8': |
output_toggle(S108A); |
// output_toggle(OS108A); |
break; |
case '9': |
output_toggle(S109A); |
output_toggle(OS109A); |
break; |
case 'a': |
output_toggle(S110J); |
output_toggle(S110N); |
// output_toggle(OS110J); |
output_toggle(OS110N); |
break; |
} |
} |
330,56 → 318,48 |
} |
|
run(103V); // Rizeni rolet za behu |
run(104V); |
// run(104V); |
run(104J); |
run(207V); |
|
switch(r110N) // Zaluzie ma specielni rizeni |
{ |
case STOP: |
OFF(R110NU); |
OFF(R110ND); |
OFF(OR110NU); |
OFF(OR110ND); |
break; |
case GO_UP: |
ON(R110NU); |
OFF(R110ND); |
OFF(OR110ND); |
ON(OR110NU); |
if(tr110N==0) {r110N=STOP;} |
break; |
case GO_DOWN: |
OFF(R110NU); |
ON(R110ND); |
OFF(OR110NU); |
ON(OR110ND); |
if(tr110N==0) {r110N=STOP;} |
break; |
case REVERS_UP: |
OFF(R110NU); |
OFF(R110ND); |
OFF(OR110NU); |
OFF(OR110ND); |
if(tr110N==0) {r110N=GO_UP; tr110N=GO_ZALUZIE;} // Nahoru pouze kratce na otevreni zaluzie |
break; |
case REVERS_DOWN: |
OFF(R110NU); |
OFF(R110ND); |
if(tr110N==0) {r110N=GO_DOWN; tr110N=2*GO_ZALUZIE;} // Dolu jede dele, aby se najelo na koncak a zatemnilo. |
OFF(OR110NU); |
OFF(OR110ND); |
if(tr110N==0) {r110N=GO_DOWN; tr110N=GO_ZALUZIE;} // Dolu take kratce pouze na zaklopeni zaluzie |
break; |
} |
/* |
switch(r110A) |
{ |
case GO_UP: |
printf("U"); |
break; |
case GO_DOWN: |
printf("D"); |
break; |
case REVERS_UP: |
printf("R"); |
break; |
case REVERS_DOWN: |
printf("E"); |
break; |
case STOP: |
printf("S"); |
break; |
} |
*/ |
|
// mistni vypinace z 2. n.p. |
if(s201AV!=IS201AV) {s201AV=IS201AV; output_toggle(OS102A); delay_ms(100); continue;} |
if(s201AZ!=IS201AZ) {s201AZ=IS201AZ; output_toggle(OS102A); delay_ms(100); continue;} |
if(s207AJ!=IS207AJ) {s207AJ=IS207AJ; output_toggle(OS207A); delay_ms(100); continue;} |
if(s203AJ!=IS203AJ) {s203AJ=IS203AJ; output_toggle(OS203A); delay_ms(100); continue;} |
if(s209AJ!=IS209AJ) {s209AJ=IS209AJ; output_toggle(OS209A); delay_ms(100); continue;} |
|
if(r207VU!=IR207VU) {r207VU=IR207VU; up(&r207V,&tr207V); delay_ms(100); continue;} |
if(r207VD!=IR207VD) {r207VD=IR207VD; down(&r207V,&tr207V); delay_ms(100); continue;} |
|
restart_wdt(); |
} |
} |