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 CCS Technical Support

'A numeric expression must appear here'...Should it?!

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







'A numeric expression must appear here'...Should it?!
PostPosted: Tue May 19, 2009 7:29 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Tue May 19, 2009 8:26 am     Reply with quote

It is likely the problem occurs before the
Code:
set_uart_speed(a);


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

View user's profile Send private message

PostPosted: Tue May 19, 2009 2:23 pm     Reply with quote

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







PostPosted: Wed May 20, 2009 2:46 am     Reply with quote

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!
PostPosted: Fri May 22, 2009 2:41 am     Reply with quote

Just a quick thanks to everyone - I wasn't aware of these limitations - I'll find a workaround I'm sure.


Thanks,
Angus
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