Professional Documents
Culture Documents
Codigo rc5 16f871
Codigo rc5 16f871
Codigo rc5 16f871
short RC5Len;
short check_byte() {
delay_us(1296);
old = PORTB.F0;
TMR0 = 0;
INTCON.T0IF = 0;
return old;
TMR0 = 0;
INTCON.T0IF = 0;
return 1;
short tmp;
short i1;
*toggle = 0;
*adress = 0;
*command = 0;
tmp = check_start_byte(0);
if (tmp == 127) goto err1;
tmp = check_start_byte(1);
if (tmp == 127) goto err1;
tmp = check_byte();
if (tmp == 127) goto err1;
if (tmp) *toggle = 1;
err1:
INTCON.T0IF = 0;
if (tmp == 127) return 1;
else return 0;
}
INTCON.GIE = 1;
INTCON.INTE = 1;
INTCON.T0IE = 1;
INTCON.T0IF = 0;
TMR0 = 0;
delay_us(432);
return TMR0 - 2;
void interrupt() {
if (INTCON.T0IF) {
count++;
if (count == 200) count = 0;
TMR0 = 0;
INTCON.T0IF = 0;
INTCON.T0IE = 1;
}
if (INTCON.INTF) {
error = read_rc5(&togg, &adr, &comm);
count = 0;
INTCON.INTF = 0;
}
}
void main() {
RC5Len = rc5_init(14);
TRISB.F0 = 1;
while (1) {
if (adr == 0) {
if (togg) {
//some code
if (count > 60) comm = 0;
}
else {
// again some code
}
if (error) {
error = 0;
// error handling
}
}
}