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

Question about constants?

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



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Question about constants?
PostPosted: Tue Sep 14, 2004 1:44 pm     Reply with quote

Ok if I understand this correctly and please point out if I do not have it right.

Ok if I declare a constant as in this.


Code:

const char AT[3][25] =  "ATD01110000001",
                        "ATXX",
                        "ATXXX";


The compiler programs this in to PIC program memory (ROM) space. The compiler also puts in code to copy the constants to RAM on start up.

Ok if all that is true I don’t see the code in the list file to copy the constants to RAM.
How do I fine the address in RAM in the list file? I would like to review the data to see if it is correct in the ICD RAM window.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 2:01 pm     Reply with quote

Quote:

The compiler programs this in to PIC program memory (ROM) space.


The compiler only puts the data in ROM if you reference it in your
program. The way that you access the data affects how the compiler
stores it in ROM. If you access just one byte of the data, the compiler
will put in code to fetch that byte as immediate data with a MOVLW
instruction. The rest of the data (ie., the strings) won't even appear
in ROM. Example:

c = AT[0][0];

If you use variables as the array indexes, then the compiler will
put the entire strings into ROM. Example:

c = AT[i][k];

Quote:
The compiler also puts in code to copy the constants to RAM on start up.

This is not true. If you use the array index method of accessing the
strings, then the compiler will put in code at the start of the strings
to fetch them, one byte at a time, using the RETLW instruction.
This code is executed if you use printf() to display the strings (for example).


Also, to see the strings in ROM (if they are put in by the compiler)
you need to View Program Memory in MPLAB, or edit the .H file for
your PIC and temporarily comment out the #nolist statement at the
start of the file. Then you can view the strings in the .LST file.
Ttelmah
Guest







Re: Question about constants?
PostPosted: Tue Sep 14, 2004 2:42 pm     Reply with quote

Tom-H-PIC wrote:
Ok if I understand this correctly and please point out if I do not have it right.

Ok if I declare a constant as in this.


Code:

const char AT[3][25] =  "ATD01110000001",
                        "ATXX",
                        "ATXXX";


The compiler programs this in to PIC program memory (ROM) space. The compiler also puts in code to copy the constants to RAM on start up.

Ok if all that is true I don’t see the code in the list file to copy the constants to RAM.
How do I fine the address in RAM in the list file? I would like to review the data to see if it is correct in the ICD RAM window.

Worth saying, that if you do want the values copied to RAM, just remove the 'const' declaration. Without this, the aray will be a RAM array, which will be initialised with the specified values from ROM on boot...

Best Wishes
Tom-H-PIC



Joined: 08 Sep 2003
Posts: 105
Location: New Castle, DE

View user's profile Send private message

Ok compiler not having pointers to constants ISSUES!
PostPosted: Tue Sep 14, 2004 3:54 pm     Reply with quote

I use the constants above on this code.

Code:

if (strncmp(Rxcom, AT[0], 3) == 0){  //this is a dial command
      if (strcmp(Rxcom,AT[0]) == 0){ //this is a Blue Radio command
         BR_error = 0;  //clear error counter
         ok_ctr = 0; //clear OK counter
         BR_on = 0; BR_reset = 0;   //Turn off Blue Radio
         BR_Online = False; //let software that phone is off line
         BR_initz = True;  //turn on initialization fuction to look for new BT phone
         BR_initz_timer = 2;  //off timer set for one second
         return;} //get out of fuction

   }


The compiler gives this error
Error[51] :A numeric expression must appear here

Seeing as strncmp uses pointers to the strings this is why I get the error correct?

So how do I make a look up function for looking up a string that is received in the serial port and then act on it?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 14, 2004 4:12 pm     Reply with quote

Quote:
Seeing as strncmp uses pointers to the strings this is why I get the error correct ?

You can't use pointers to constant strings in CCS. The strncmp()
function expects the strings to be in RAM. You first have to use the
CCS function strcpy() to copy the constant string to a RAM array,
and then pass the address of the RAM array to strncmp().
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