|
|
View previous topic :: View next topic |
Author |
Message |
Allan
Joined: 20 Dec 2009 Posts: 23
|
ENUM ID values not unique |
Posted: Sat Jun 05, 2010 11:21 pm |
|
|
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
|
|
Posted: Sun Jun 06, 2010 12:54 pm |
|
|
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:
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
|
|
Posted: Sun Jun 06, 2010 1:35 pm |
|
|
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
|
|
Posted: Sun Jun 06, 2010 3:15 pm |
|
|
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
|
|
Posted: Thu Jul 01, 2010 10:47 pm |
|
|
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
|
|
Posted: Fri Jul 02, 2010 6:30 am |
|
|
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
|
|
Posted: Sat Jul 03, 2010 8:30 pm |
|
|
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: 19520
|
|
Posted: Sun Jul 04, 2010 3:01 am |
|
|
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
|
Having the same problem. |
Posted: Fri Jul 09, 2010 4:36 pm |
|
|
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. |
|
|
|
|
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
|