From dc0f1b195bb5a76c37cd7bc8942fd0070d6954e1 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 9 Oct 2013 19:56:40 +0200 Subject: directly store bit mask in POS --- main.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/main.c b/main.c index 15726e8..15f4cee 100644 --- a/main.c +++ b/main.c @@ -149,7 +149,7 @@ ISR(INT1_vect) DDRD = 0; LASTCMD = 0; BUF = 0; - POS = 0; + POS = 1; APOS = 0; asm volatile ("wdr"); EIFR |= _BV(INTF1); @@ -159,21 +159,23 @@ ISR(INT1_vect) * Line was high for > 15us - got a "write 0" */ if (LCNTL > 15) { - POS++; + // nothing to do } /* * Line was high for <= 15us - got a "write 1". Might also be a * "read", so only do stuff if we don't have a command set */ else { - BUF |= _BV(POS); - POS++; + BUF |= POS; } /* * We received 8 command bits. Store the command and switch to * write mode (also, store the first byte to be sent) */ - if (POS == 7) { + if (POS != 0x80) { + POS <<= 1; + } + else { LASTCMD = BUF; POS = 1; APOS = 0; @@ -291,11 +293,6 @@ ISR(INT1_vect) BYTE = ~ADDR2; else if (APOS == 7) BYTE = ~ADDR1; - - else if (APOS == 8) { - LASTCMD = 0; - POS = 0; - } } } -- cgit v1.2.3