From af7f315f7f64720804086bfb6f14a217e9b97d39 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 9 Oct 2013 19:47:31 +0200 Subject: check !LASTCMD earlier --- main.c | 48 ++++++++++++++++++++++++------------------------ 1 file changed, 24 insertions(+), 24 deletions(-) (limited to 'main.c') diff --git a/main.c b/main.c index 5d0e9ec..15726e8 100644 --- a/main.c +++ b/main.c @@ -150,37 +150,37 @@ ISR(INT1_vect) LASTCMD = 0; BUF = 0; POS = 0; + APOS = 0; asm volatile ("wdr"); EIFR |= _BV(INTF1); } - /* - * Line was high for > 15us - got a "write 0" - */ - else if (LCNTL > 15) { - if (!LASTCMD) + else if (!LASTCMD) { + /* + * Line was high for > 15us - got a "write 0" + */ + if (LCNTL > 15) { POS++; - } - /* - * 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 { - if (!LASTCMD) { + } + /* + * 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++; } - } - /* - * We received 8 command bits. Store the command and switch to - * write mode (also, store the first byte to be sent) - */ - if (!LASTCMD && (POS == 7)) { - LASTCMD = BUF; - POS = 1; - APOS = 0; - BYTE = ~ADDR8; - EEAR = 0; - EIFR |= _BV(INTF1); + /* + * We received 8 command bits. Store the command and switch to + * write mode (also, store the first byte to be sent) + */ + if (POS == 7) { + LASTCMD = BUF; + POS = 1; + APOS = 0; + BYTE = ~ADDR8; + EEAR = 0; + EIFR |= _BV(INTF1); + } } } else { -- cgit v1.2.3