avr-gcc-list
[Top][All Lists]
Advanced

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

Re: [avr-gcc-list] Bug? with switch statement - other case !!


From: Christoph Plattner
Subject: Re: [avr-gcc-list] Bug? with switch statement - other case !!
Date: Tue, 17 Dec 2002 00:21:37 +0100
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.1) Gecko/20020830

Hello to all !

I had the same problem about one-to-two year ago !!
In my switch()-case statement, only the first entry was taken.
This was no coding problem !!!
I analysed the assembler code, and it definitly clobbered all other
branches.

So there may be a compiler branch, which have a buggy switch()-case
implementation !!!

I rewrote the code using `if ... else if .... else if .... else' to work
around the bug.

(I cannot remeber the comiler version, it was one cvs checkout in the
beginnig of AVR C being in mainstream).

Bye
Christoph Plattner


Hendrix, Jeff wrote:
I installed gcc 20021209 and now the code works perfectly (I didn't make any
changes to the source, only the makefile).
I'll try changing my variable to unsigned and see if that works (I'll have
to wait until tonight, I uninstalled the old gcc from my machine here),
although I don't think it should matter since it's only dealing with this
data in 8 bits.

To answer Eric's question (or reply to his comment), I have the high nibble
set as inputs and writing a 0xf0 to portc will turn on the pull up
resistors. The keypad will then pull the pin to ground when a button is
pressed and I only want to respond when 1 button is pressed (so I only have
4 valid cases).

-jeff

-----Original Message-----
From: Hendrix, Jeff [mailto:address@hidden
Sent: Friday, December 13, 2002 12:07 PM
To: address@hidden
Subject: [avr-gcc-list] Bug? with switch statement


I'm compiling the code below with 2002-06-25 release from avrfreaks.
I was originally testing this code on a mega128, the I tried in in avr
studio with the same results. I also tried compiling it to an 8515 target
and still get the same results.
What's happening is the switch statement will only ever take the last case.
To simulate this, you need to turn on the high nibble on port C pins (to
simulate the pullups), and then turn off one of the bits in the high nibble.
The only time it takes one of the case paths is when bit 8 is off (0x70),
all the other times it just ignores the other cases.
Anyone have any ideas?

thanks
-jeff

#include <io.h>

char ReadKeyPad(void)
{
   char readPort = 0;
   char curKey = 0;

   // check ROW1
        PORTC = 0xfe;  // turn on pull ups and ground row 1
        readPort = PINC&0xf0;   // check just the high nibble
        switch (readPort) {
        case 0xe0:     // key 1 held down
                curKey = 1;
                break;
        case 0xd0:     // key 2 held down
                curKey = 2;
                break;
        case 0xb0:     // key 3 held down
                curKey = 3;
                break;
        case 0x70:     // key 4 held down
                curKey = 4;
                break;
        }

        PORTC = 0;
   return curKey;
}


int main(void)
{
        char kp;
        DDRC = 0x0f;
        PORTC = 0x00;

   while (1) {
                kp = ReadKeyPad();
        }
        return 0;
}
avr-gcc-list at http://avr1.org
avr-gcc-list at http://avr1.org





--
-------------------------------------------------------
private:        address@hidden
company:        address@hidden

avr-gcc-list at http://avr1.org



reply via email to

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