![](templates/subSilver/images/CCSLogo.jpg) |
![CCS C Software and Maintenance Offers](templates/subSilver/images/forumAd6.jpg) |
View previous topic :: View next topic |
Author |
Message |
mirberti Guest
|
problem with expression & constant |
Posted: Tue Jun 01, 2004 2:41 am |
|
|
Hi,
I write this code but when I compile it, the compiler return me an error :
"EXPRESSION MUST EVALUATE TO A CONSTANT"
why ?? how can I resolve this problem ??
Thanks Mirko
Code: |
int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};
for (i=0;i<N_INGRESSI+1;i++){
if( input(PortaI[i]) ) Ingressi[i] = 0x01;
else Ingressi[i] = 0x00;
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: problem with expression & constant |
Posted: Tue Jun 01, 2004 5:42 am |
|
|
mirberti wrote: | Hi,
I write this code but when I compile it, the compiler return me an error :
"EXPRESSION MUST EVALUATE TO A CONSTANT"
why ?? how can I resolve this problem ??
Thanks Mirko
Code: |
int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};
for (i=0;i<N_INGRESSI+1;i++){
if( input(PortaI[i]) ) Ingressi[i] = 0x01;
else Ingressi[i] = 0x00;
}
|
|
Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
mirberti Guest
|
Re: problem with expression & constant |
Posted: Tue Jun 01, 2004 9:42 am |
|
|
thanks, but in my old firmwware there was a solution with SWITH.
Now I would write a scalable routine with I can use in all my program only changing a define or a constant.
Regards Mirko
Ttelmah wrote: | mirberti wrote: | Hi,
I write this code but when I compile it, the compiler return me an error :
"EXPRESSION MUST EVALUATE TO A CONSTANT"
why ?? how can I resolve this problem ??
Thanks Mirko
Code: |
int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};
for (i=0;i<N_INGRESSI+1;i++){
if( input(PortaI[i]) ) Ingressi[i] = 0x01;
else Ingressi[i] = 0x00;
}
|
|
Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).
Best Wishes |
|
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah Guest
|
Re: problem with expression & constant |
Posted: Tue Jun 01, 2004 10:19 am |
|
|
mirberti wrote: | thanks, but in my old firmwware there was a solution with SWITH.
Now I would write a scalable routine with I can use in all my program only changing a define or a constant.
Regards Mirko
Ttelmah wrote: | mirberti wrote: | Hi,
I write this code but when I compile it, the compiler return me an error :
"EXPRESSION MUST EVALUATE TO A CONSTANT"
why ?? how can I resolve this problem ??
Thanks Mirko
Code: |
int const PortaI[] = {PIN_B0, PIN_B1, PIN_C2, PIN_B5};
for (i=0;i<N_INGRESSI+1;i++){
if( input(PortaI[i]) ) Ingressi[i] = 0x01;
else Ingressi[i] = 0x00;
}
|
|
Basically, the 'input' statement (and the equivalent output one), are not normal functions. They are instructions to the compiler to access a single pin, which must not change after compile time. The compiler cannot handle these funtions receiving anything other than a fixed value. Though the individual values in your array are fixed, by selecting using a variable, you are exceeding what the compiler can do with these functions.
There are a huge number of solutions. Probably the simplest, is just to use a switch to access the required pin. Alternatively, you can just write your own I/O function using a mask (but in your case, since the required locations are on two ports, this involves more work).
Best Wishes |
|
The switch solution will still work. Adter all you only have four possible pins to be used.
Best Wishes |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Jun 01, 2004 11:06 am |
|
|
Look at the following thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=18233
Mark has posted two functions for output_high and
output_low that let you pass a CCS-style pin number
to the functions as a variable, instead of a constant.
Look for these function names in his post:
my_output_high()
my_output_low() |
|
![](templates/subSilver/images/spacer.gif) |
|
|
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
|