5,19 → 5,20 |
#define REVERS 2 // 2*256 ms = 0,5 s |
#define GO 117 // 117*256 ms = 30 s |
#define GO_ZALUZIE 5 // 5*256 ms = 1,25 s |
#define RECEIVE 12 // 3 s |
|
#define S105A PIN_A0 |
#define R110AU PIN_A1 |
#define R110AD PIN_A2 |
#define R110NU PIN_A1 |
#define R110ND PIN_A2 |
#define S104A PIN_A3 |
#define R104AU PIN_A4 |
#define R104AD PIN_A5 |
#define R104BU PIN_A6 |
#define R104BD PIN_A7 |
#define R104VU PIN_A4 |
#define R104VD PIN_A5 |
#define R104JU PIN_A6 |
#define R104JD PIN_A7 |
|
#define S103A PIN_B0 |
#define R103AU PIN_B1 |
#define R103AD PIN_B2 |
#define S103J PIN_B0 |
#define R103VU PIN_B1 |
#define R103VD PIN_B2 |
#define S106A PIN_B3 |
#define S107A PIN_B4 |
#define S109A PIN_B5 |
32,13 → 33,13 |
//#define PIN_C6 31766 //TX |
//#define PIN_C7 31767 //RX |
|
#define S101A PIN_D0 |
#define S105D PIN_D1 |
#define S102A PIN_D2 |
#define S110C PIN_D3 |
#define S108A PIN_D4 |
#define S201A PIN_D5 |
#define S110B PIN_D6 |
//#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 PIN_E0 31776 |
95,16 → 96,18 |
|
typedef enum {GO_UP, GO_DOWN, REVERS_UP, REVERS_DOWN, STOP} state; |
|
state r103A, r110A, r104A, r104B; // Stavy rolet |
int8 tr103A, tr110A, tr104A, tr104B; // Casovace rolet |
state r103V, r110N, r104V, r104J; // Stavy rolet |
int8 tr103V, tr110N, tr104V, tr104J; // Casovace rolet |
int8 timer; // Casovac komunikace |
|
#int_TIMER0 |
void TIMER0_isr(void) |
{ |
if(tr103A>0) tr103A--; |
if(tr110A>0) tr110A--; |
if(tr104A>0) tr104A--; |
if(tr104B>0) tr104B--; |
if(tr103V>0) tr103V--; |
if(tr110N>0) tr110N--; |
if(tr104V>0) tr104V--; |
if(tr104J>0) tr104J--; |
if(timer>0) timer--; |
output_toggle(LED2); |
} |
|
174,162 → 177,185 |
|
void main() |
{ |
char c; |
char buf[10]; |
|
if(restart_cause()!= WDT_TIMEOUT) |
{ |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_psp(PSP_DISABLED); |
setup_spi(SPI_SS_DISABLED); |
setup_wdt(WDT_ON); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
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); |
|
OFF(S105A); // Vsechno zhasni a zastav |
OFF(R110AU); |
OFF(R110AD); |
OFF(S104A); |
OFF(R104AU); |
OFF(R104AD); |
OFF(R104BU); |
OFF(R104BD); |
OFF(S103A); |
OFF(R103AU); |
OFF(R103AD); |
OFF(S106A); |
OFF(S107A); |
OFF(S109A); |
OFF(S101A); |
OFF(S105D); |
OFF(S102A); |
OFF(S110C); |
OFF(S108A); |
OFF(S201A); |
OFF(S110B); |
setup_adc_ports(NO_ANALOGS|VSS_VDD); |
setup_adc(ADC_CLOCK_DIV_2); |
setup_psp(PSP_DISABLED); |
setup_spi(SPI_SS_DISABLED); |
setup_wdt(WDT_OFF); |
setup_timer_0(RTCC_INTERNAL|RTCC_DIV_1); |
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); |
|
r103A=STOP; // Rolety jsou zastaveny |
r110A=STOP; |
r104A=STOP; |
r104B=STOP; |
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); |
|
enable_interrupts(INT_TIMER0); |
enable_interrupts(GLOBAL); |
} |
r103V=STOP; // Rolety jsou zastaveny |
r110N=STOP; |
r104V=STOP; |
r104J=STOP; |
|
output_high(LED1); // Indikace restartu |
delay_ms(100); |
output_low(LED1); |
delay_ms(30); |
output_high(LED1); |
restart_wdt(); |
delay_ms(100); |
output_low(LED1); |
delay_ms(30); |
output_high(LED1); |
restart_wdt(); |
|
enable_interrupts(INT_TIMER0); |
enable_interrupts(GLOBAL); |
|
CREN=0; CREN=1; // Reinitialise USART |
|
while(TRUE) |
{ |
if(kbhit()) |
|
if(kbhit()) // Chce po nas nekdo neco? |
{ |
c=getc(); |
if(c=='S') |
buf[0]=getc(); |
if((buf[0]=='S')||(buf[0]=='R')) // Jinym znakem nesmi zacinat prikaz |
{ |
if(getc()=='1') |
int8 n=0; // Ukazatel do prijimaciho bufferu |
timer=RECEIVE; // Timeout pro prijem znaku |
|
do |
{ |
switch(getc()) |
if(kbhit()) // Je dalsi znak? |
{ |
case '1': |
output_toggle(S101A); |
break; |
case '2': |
output_toggle(S102A); |
break; |
case '3': |
output_toggle(S103A); |
break; |
case '4': |
output_toggle(S104A); |
break; |
case '5': |
c=getc(); |
if(c=='A') {output_toggle(S105A);} |
if(c=='D') {output_toggle(S105D);} |
break; |
case '6': |
output_toggle(S106A); |
break; |
case '7': |
output_toggle(S107A); |
break; |
case '8': |
output_toggle(S108A); |
break; |
case '9': |
output_toggle(S109A); |
break; |
case 'a': |
output_toggle(S110B); |
output_toggle(S110C); |
break; |
n++; |
buf[n]=getc(); |
} |
} |
} |
|
if(c=='R') |
{ |
if(getc()=='1') |
} while ((buf[n]!='\r')&&(timer>0)&&(n<7)); |
|
if (timer==0) { CREN=0; CREN=1; } // Reinitialise USART |
|
output_toggle(LED1); // Ukonceni prijimani prikazu |
|
if((timer>0)) |
{ |
switch(getc()) |
|
if((buf[0]=='S')&&(n>=4)) // Zmena stavu svetla |
{ |
case '3': |
getc(); // A |
if((getc()=='U')) {up(&r103A,&tr103A);} else {down(&r103A,&tr103A);} |
break; |
case '4': |
c=getc(); |
if(c=='A') if((getc()=='U')) {up(&r104A,&tr104A);} else {down(&r104A,&tr104A);} |
if(c=='B') if((getc()=='U')) {up(&r104B,&tr104B);} else {down(&r104B,&tr104B);} |
break; |
case 'a': |
getc(); // A |
if((getc()=='U')) {up(&r110A,&tr110A);} else {down(&r110A,&tr110A);} |
break; |
if(buf[1]=='1') |
{ |
switch(buf[2]) |
{ |
case '2': |
output_toggle(S102A); |
break; |
case '3': |
output_toggle(S103J); |
break; |
case '4': |
output_toggle(S104A); |
break; |
case '5': |
if(buf[3]=='A') {output_toggle(S105A);} |
if(buf[3]=='Z') {output_toggle(S105Z);} |
break; |
case '6': |
output_toggle(S106A); |
break; |
case '7': |
output_toggle(S107A); |
break; |
case '8': |
output_toggle(S108A); |
break; |
case '9': |
output_toggle(S109A); |
break; |
case 'a': |
output_toggle(S110J); |
output_toggle(S110N); |
break; |
} |
} |
} |
|
if((buf[0]=='R')&&(n>=5)) // Zmena stavu rolety |
{ |
if(buf[1]=='1') |
{ |
switch(buf[2]) |
{ |
case '3': |
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);} |
break; |
case 'a': |
if((buf[4]=='U')) {up(&r110N,&tr110N);} else {down(&r110N,&tr110N);} |
break; |
} |
} |
} |
|
} |
} |
|
output_toggle(LED1); // Prijmuli jsme cely prikaz |
} |
else |
{ |
run(103A); |
run(104A); |
run(104B); |
|
run(103V); // Rizeni rolet za behu |
run(104V); |
run(104J); |
|
switch(r110A) |
{ |
case STOP: |
OFF(R110AU); |
OFF(R110AD); |
break; |
case GO_UP: |
ON(R110AU); |
OFF(R110AD); |
if(tr110A==0) {r110A=STOP;} |
break; |
case GO_DOWN: |
OFF(R110AU); |
ON(R110AD); |
if(tr110A==0) {r110A=STOP;} |
break; |
case REVERS_UP: |
OFF(R110AU); |
OFF(R110AD); |
if(tr110A==0) {r110A=GO_UP; tr110A=GO_ZALUZIE;} |
break; |
case REVERS_DOWN: |
OFF(R110AU); |
OFF(R110AD); |
if(tr110A==0) {r110A=GO_DOWN; tr110A=GO_ZALUZIE;} |
break; |
} |
switch(r110N) // Zaluzie ma specielni rizeni |
{ |
case STOP: |
OFF(R110NU); |
OFF(R110ND); |
break; |
case GO_UP: |
ON(R110NU); |
OFF(R110ND); |
if(tr110N==0) {r110N=STOP;} |
break; |
case GO_DOWN: |
OFF(R110NU); |
ON(R110ND); |
if(tr110N==0) {r110N=STOP;} |
break; |
case REVERS_UP: |
OFF(R110NU); |
OFF(R110ND); |
if(tr110N==0) {r110N=GO_UP; tr110N=GO_ZALUZIE;} |
break; |
case REVERS_DOWN: |
OFF(R110NU); |
OFF(R110ND); |
if(tr110N==0) {r110N=GO_DOWN; tr110N=GO_ZALUZIE;} |
break; |
} |
/* |
switch(r110A) |
{ |
350,7 → 376,6 |
break; |
} |
*/ |
restart_wdt(); |
} |
restart_wdt(); |
} |
} |