|
|
View previous topic :: View next topic |
Author |
Message |
Angus Guest
|
'A numeric expression must appear here'...Should it?! |
Posted: Tue May 19, 2009 7:29 am |
|
|
Hi all,
This may well be a really stupid question, but I am having problems calling a function which is expecting an 8 bit integer. The function is as follows:
Code: | void set_uart_speed(int8 s)
{
switch(s) // Set UART baud rate
{
case 0: set_uart_speed(9600); break;
case 1: set_uart_speed(19200); break;
case 2: set_uart_speed(38400); break;
}
} |
And I need to pass it a local variable to set the UART speed accordingly, example as follows:
Code: | a = 1;
set_uart_speed(a);
|
However this results in the 'A numeric expression must appear here' error. Passing it a constant (i.e. 'set_uart_speed(0);') works fine. What am I missing?!
Thanks!
Angus |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1635 Location: Perth, Australia
|
|
Posted: Tue May 19, 2009 8:26 am |
|
|
It is likely the problem occurs before the
Look for a missing ; or brace. _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue May 19, 2009 2:23 pm |
|
|
That function doesn't accept a variable as a parameter. It must be
a constant. From the manual:
Quote: |
set_uart_speed( )
Syntax: set_uart_speed (baud, [stream, clock])
Parameters: baud is a constant
|
The reason for this is undoubtedly to create more compact code.
The conversion of '9600' to suitable register values is done at
compile-time, and it compiles to only 5 lines. If this was done
at run-time it would require much more code.
Code: |
00314 .................... set_uart_speed(9600);
0017 3019 00315 MOVLW 19
0018 1683 00316 BSF 03.5
0019 0099 00317 MOVWF 19
001A 30A6 00318 MOVLW A6
001B 0098 00319 MOVWF 18 |
The basic CCS philosophy is to keep the ROM-usage low by doing
computations at compile-time, if possible. This means that in many
cases the functions are less flexible, because they don't accept
variables as parameters. It's a trade-off that makes sense for the
16F-series and small-to-medium 18F PICs. |
|
|
Ttelmah Guest
|
|
Posted: Wed May 20, 2009 2:46 am |
|
|
The actual core of the problem, is that a lot of CCS 'functions', are not. In many cases, they are internal macros. Now the original code, is attempting to overload the CCS function, by allowing an 8bit integer to select which of the CCS 'set_uart_speed' functions should be called. If the CCS code, was a function, and it's variable typed as an int16, this would work, but since it is actually a macro, and written to require a constant only, the overload won't work.
The basic code will work fine, if you just change the name. Call the function (say) my_set_uart_speed, and it'll work.
Best Wishes |
|
|
Angsu Guest
|
Thanks! |
Posted: Fri May 22, 2009 2:41 am |
|
|
Just a quick thanks to everyone - I wasn't aware of these limitations - I'll find a workaround I'm sure.
Thanks,
Angus |
|
|
|
|
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
|