CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

ENUM ID values not unique

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

ENUM ID values not unique
PostPosted: Sat Jun 05, 2010 11:21 pm     Reply with quote

Hi everybody,

I'm using 4.104 compiler version with a 18F2321.

I have the following declaration:

Quote:

enum Modes{InternalMode, ExternalMode, EncoderMode, StandByMode};


When I mouse over this statement I get the wrong constant values -

InternalMode = 0
ExternalMode = 2
EncoderMode = 0
StandByMode = 0

The manual says:
" The ids in the list are each created as a constant. By default the first id is set to zero and they increment by one. "


I have a simple test if-else if statement that fails - it never gets to EncoderMode since it is exiting at InternalMode test.

Code:

if(CurrentMode == InternalMode)
   Display = Display + 1;
else if(CurrentMode == ExternalMode)
   Display = Display +2;
else if(CurrentMode == EncoderMode)
   Display = Display + 3;


Any idea what's going on? Am I wrong to expect the mouse over to show the constants to be assigned 0 to 3?

Thanks, Al
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 12:54 pm     Reply with quote

The mouse-over would be some kind of IDE issue. The actual code works.
(You didn't say what IDE you're using).
I installed vs. 4.104 and compiled the test program shown below.
Here's the output from the MPLAB simulator. It's correct.
Quote:

InternalMode: 0
ExternalMode: 1
EncoderMode: 2
StandbyMode: 3

Code:

#include <18F2321.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

enum Modes{InternalMode, ExternalMode, EncoderMode, StandByMode};

//======================================
void main(void)
{
printf("InternalMode: %u\r", InternalMode);
printf("ExternalMode: %u\r", ExternalMode);
printf("EncoderMode: %u\r", EncoderMode);
printf("StandbyMode: %u\r", StandbyMode);

while(1);
}


Then I made the test program shown below with your 'if-else' statements
and it gave this result, which is correct:
Quote:

Display = 3

Code:

#include <18F2321.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)

enum Modes{InternalMode, ExternalMode, EncoderMode, StandByMode};

//======================================
void main(void)
{
int8 CurrentMode;
int8 Display;

Display = 0;
CurrentMode = 2;

if(CurrentMode == InternalMode)
   Display = Display + 1;
else if(CurrentMode == ExternalMode)
   Display = Display +2;
else if(CurrentMode == EncoderMode)
   Display = Display + 3;

printf("Display = %u\r", Display);

while(1);
}
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 1:35 pm     Reply with quote

Hi PCM programmer,

I just compiled your code and it still gives me wrong ID's. I'll reload CCS's IDE and post if that does not solve the problem.

Thanks for your help.

Al
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Sun Jun 06, 2010 3:15 pm     Reply with quote

Hi everybody,

Reloading the compiler and CCS' IDE (now V. 4.103) did not solve the problem, but I found an interesting clue.

I simplified the code as much as possible

Code:

#include <18F2321.h>
#fuses XT,NOWDT,PUT,BROWNOUT,NOLVP
#use delay(clock=10000000)

enum Modes{InternalMode, ExternalMode, EncoderMode, StandByMode};

void main(void)
   {
   while(1)
      {}
   }


I get the correct ID values (0,1,2,3) when I compile the code. It is only after I turn on the ICD-U64 debugger that I get the problem.

The correct compiler mouse over has black lettering on a light blue background, The incorrect mouse over with the IDE uses blue lettering on a yellow background. Different software!

I think the problem is in the ICD-U64. I'll try the programmer at work tomorrow and see what happens.

Al
semaphore



Joined: 01 Jul 2010
Posts: 2

View user's profile Send private message

PostPosted: Thu Jul 01, 2010 10:47 pm     Reply with quote

I've the same problem here. I'm using CCS IDE version 4.107 and PCB, PCM, PCH, PCD version 4.107 with ICD-U64. Please help.
Allan



Joined: 20 Dec 2009
Posts: 23

View user's profile Send private message

PostPosted: Fri Jul 02, 2010 6:30 am     Reply with quote

semaphore wrote:
I've the same problem here. I'm using CCS IDE version 4.107 and PCB, PCM, PCH, PCD version 4.107 with ICD-U64. Please help.


The best work around is to define each ENUM value as a constant.

Foe example, use
Quote:


const int8 InternalMode=0, ExternalMode=1, EncoderMode=2, StandByMode=3;



instead of
Quote:


enum Modes{InternalMode, ExternalMode, EncoderMode, StandByMode};



This works fine. I'll keep bugging CCS about this until get a response.

Al
semaphore



Joined: 01 Jul 2010
Posts: 2

View user's profile Send private message

PostPosted: Sat Jul 03, 2010 8:30 pm     Reply with quote

Thanks Al,

I like to see this fix as well. It just kind of bug me that the simple enum doesn't work the way it should.
Ttelmah



Joined: 11 Mar 2010
Posts: 19384

View user's profile Send private message

PostPosted: Sun Jul 04, 2010 3:01 am     Reply with quote

The thing is that the enum does. It appears to be a problem with the way that the IDE 'understands' enum values. Have used many dozens of enum's with a hardware ICE, and in real code, and the values are right. It is only in the IDE debugging environment, that the values go wrong....

Best Wishes
ForrestJohnson



Joined: 09 Jul 2010
Posts: 1

View user's profile Send private message

Having the same problem.
PostPosted: Fri Jul 09, 2010 4:36 pm     Reply with quote

Ya, I've spent quite a bit of time dealing with this problem and it seems like it cascades into other areas causing more debugger-related problems. Like arrays of structs containing enums are showing incorrect data and size.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group