avr-chat
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-chat] Mega644 bit test problem


From: Erwan MARC
Subject: Re: [avr-chat] Mega644 bit test problem
Date: Mon, 20 Jul 2009 08:43:07 +0200
User-agent: Thunderbird 2.0.0.22 (Windows/20090605)

tarmigan a écrit :
snip
#define CLOCK_TIMEOUT    2000
#define ASYNCPIN    PORTB
#define ASYNCCLK    0
#define ASYNCDATA    3

   for (i = 0 ; i < 16 ; ++i)
   {
       while ((ASYNCPIN & _BV(ASYNCCLK)) != 0)        // Wait for clock low
       {
       if (mSecdowncnt == 0)
       {
           noclock = 1;
           break;                    // Timeout
       }
       }

       result = result >> 1;
       if ((ASYNCPIN & _BV(ASYNCDATA)) != 0)
       {
       result |= 0x8000;
       }

       while ((ASYNCPIN & _BV(ASYNCCLK)) != 1)        // Wait for clock

This line is probably the problem.

This works fine. I want, however to use portb bits 1 & 3 for clock &
data. I simply change to #define ASYNCCLK    1
and re-compile
Now, nothing works and the code generated is much smaller (0xe5 bytes
instead of 0x193 bytes for the working variant).

_BV(0)==1 but _BV(1)==2, so when you do ((value & _BV(1)) != 1), it's
never false because the possible values of (ASYNCPIN & _BV(1)) are 0
or 2, never 1.

I would try to write these kinds of statements as
        while( !(ASYNCPIN & _BV(ASYNCCLK)) ) {
                  blah, blah;
        }

-Tarmigan


Another way to to that is (data & MASK == MASK): this will solve question in any situation if MASK is modified and doesn't assume the fact that for C language "!=0" stands for TRUE.







reply via email to

[Prev in Thread] Current Thread [Next in Thread]