Code:
#endif /* RC5_INT */
{ code_t _code = code; uint8_t _nint = nint; uint8_t tcnt0 = TCNT0; TCNT0 = 0; if (0 == _nint) { /* INTx on both edges */ #if (RC5_INT == RC5_INT0) MCUCR = (MCUCR | (1 << ISC00)) & ~ (1 << ISC01); #elif (RC5_INT == RC5_INT1) MCUCR = (MCUCR | (1 << ISC10)) & ~ (1 << ISC11); #endif /* RC5_INT */ TIFR = (1 << TOV0); TIMSK |= (1 << TOIE0); _code.w = 0; } else { /* Number of bits of the just elapsed period */ uint8_t n = 1; /* Bits received so far */ uint8_t _nbits = nbits; /* is TCNT0 close to RC5_TICKS or RC5_TICKS/2 ? */ if (tcnt0 > RC5_TICKS + RC5_DELTA) goto invalid; else if (tcnt0 < RC5_TICKS/2 - RC5_DELTA) goto invalid; else if (tcnt0 > RC5_TICKS - RC5_DELTA) n = 2; else if (tcnt0 > RC5_TICKS/2 + RC5_DELTA) goto invalid; /* store the just received 1 or 2 bits */ do { _nbits++; if (_nbits & 1) { _code.w <<= 1; _code.b[0] |= _nint & 1; } } while (--n); if (0) { invalid: /* disable INTx, run into Overflow0 */ #if (RC5_INT == RC5_INT0) GICR &= ~(1 << INT0); #elif (RC5_INT == RC5_INT1) GICR &= ~(1 << INT1); #endif /* RC5_INT */ _nbits = 0; } nbits = _nbits; } code = _code; nint = 1+_nint; }
Bei den ganzen if's wird geprüft, ob der Impuls falsch ist. Wenn alles korrekt ist wird die do-while ausgeführt. Prüfe da mal was angesprungen wird.
EDIT: SCH****ß Formatierung -.-
Die if-else abfragen in der INT0 ISR mit der darauffolgenden do-while-schleife
mfg
Lesezeichen