LED stays on on new code, blinked on existing coe, and can be cleared using the button
This commit is contained in:
parent
980f8dcbfe
commit
32dd7bbee6
|
@ -50,6 +50,7 @@
|
|||
static uint8_t switches; /* save the last switch state */
|
||||
#define START 208 /* starting timer 0 value to wait up to 12ms in start_timer*/
|
||||
static uint8_t code[3] = {0xf1, 0x11, 0x11}; /* the received code (24 bits) */
|
||||
static uint8_t new = 0; /* has a new code been detected (clear using button) */
|
||||
|
||||
/* configuration bits */
|
||||
uint16_t __at(_CONFIG1) __CONFIG1 = _FCMEN_ON & /* enable fail-safe clock monitor */
|
||||
|
@ -314,8 +315,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 */
|
||||
new = 0; /* clear new code status */
|
||||
} else { /* switch 1 pressed */
|
||||
led_on(); /* test LED */
|
||||
}
|
||||
|
@ -344,7 +345,7 @@ void main (void)
|
|||
uint8_t rx = 0; /* are we receiving a pulse */
|
||||
uint8_t bit = 0; /* the current received bit */
|
||||
uint8_t time = 0; /* time since previous bitframe start, in 0.256ms steps */
|
||||
uint16_t new = 0; /* is the code new */
|
||||
uint16_t rc; /* return code */
|
||||
|
||||
init(); /* configure micro-controller */
|
||||
dump_codes(); /* dump codes when powering up so a logic analyzer can get them */
|
||||
|
@ -380,12 +381,16 @@ void main (void)
|
|||
bit = 0; /* restart from beginning for new code */
|
||||
}
|
||||
if (bit==24) { /* received all 24 bits */
|
||||
led_on();
|
||||
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 */
|
||||
led_on(); /* indicate activity */
|
||||
rc = save_code(); /* save code in external EEPROM */
|
||||
if (!new) { /* only switch led off if no new code has been detected (globally) */
|
||||
led_off(); /* activity finished */
|
||||
}
|
||||
if (rc==1) { /* new code saved */
|
||||
new = 1; /* remember a new code has been saved */
|
||||
led_on(); /* indicate new code detected */
|
||||
LATA |= RELAY1; /* switch relay on to make sound */
|
||||
for (rc=0; rc<1024; rc++); /* wait a bit */
|
||||
LATA &= ~RELAY1; /* switch relay off */
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue