use relay to signal new saved code

This commit is contained in:
King Kévin 2014-08-02 15:56:11 -07:00
parent 6e68b14cc9
commit 5a32c0c9a4
1 changed files with 8 additions and 2 deletions

View File

@ -76,6 +76,7 @@ void init (void) {
ANSELB = 0; /* all pins are digital */
TRISA |= RADIO; /* radio signal is an input */
TRISA &= ~(RELAY1|RELAY2); /* relays are outputs */
LATA &= ~(RELAY1|RELAY2); /* switch relays off */
TRISB |= SWITCH1|SWITCH2; /* switches are inputs (with external pull-ups) */
TRISB &= ~(LED); /* LED is an output (used a sink) */
led_off(); /* starting state */
@ -274,8 +275,8 @@ static void interrupt(void) __interrupt 0
switches ^= PORTB; /* figure out which switch changed */
if (switches&SWITCH1) { /* switch 1 changed */
if (PORTB&SWITCH1) { /* switch 1 released */
clear_memory(); /* empty saved codes */
led_off(); /* reset LED */
clear_memory();
} else { /* switch 1 pressed */
led_on(); /* test LED */
}
@ -340,8 +341,13 @@ void main (void)
}
if (bit==24) { /* received all 24 bits */
led_on();
save_code(); /* save code in external EEPROM */
new = save_code(); /* save code in external EEPROM */
led_off();
if (new==1) { /* new code saved */
LATA |= RELAY1; /* switch relay on */
for (new=0; new<1024; new++); /* wait a bit */
LATA &= ~RELAY1; /* switch relay off */
}
}
}
if (bit==0) { /* sync pulse (can be the current one it it is not a continuation */