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

String manipulation with CCS
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Ralf2



Joined: 05 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 7:33 pm     Reply with quote

Many thanks for helping PCM Programmer

I want to create a table of integers and character string in rom to access them from the main().

Regards
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 9:24 pm     Reply with quote

The test program below displays the following output in MPLAB Simulator
for compiler vs. 5.026:
Quote:

HELLO
WORLD
CONST
STRINGS

Test program:
Code:

#include <18F4520.h>
#fuses INTRC_IO, BROWNOUT, PUT, NOWDT
#use delay(clock=4M)
#use rs232(baud=9600, UART1, ERRORS)

#define NUM_STRINGS 4

const char strings[NUM_STRINGS][*] =
{
"HELLO",
"WORLD",
"CONST",
"STRINGS"
};

//===================================
void main()
{
int8 i;

for(i=0; i < NUM_STRINGS; i++)
   { 
    printf("%s \r", strings[i]);   
   }

while(1);
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Mon Jul 14, 2014 11:46 pm     Reply with quote

Apologies for the earlier syntax error.

As a comment, treat the pointer as an array.

If you declare the pointer as normal, but then use:

fred[index++]

rather than updating fred itself, it will access the elements.

Why, I don't know, but in CCS the equivalence between pointers and an array, does not work, when dealing with ROM variables.

If you look at the code, it is more difficult to access the ROM (remember that this is not directly accessible using an instruction like RAM, there has to be a 'lookup', and transfer of the data to RAM), so some 'limitations' are not surprising....
Ralf2



Joined: 05 Feb 2009
Posts: 10

View user's profile Send private message

PostPosted: Tue Jul 15, 2014 12:02 am     Reply with quote

Thanks PCM Programmer and Ttelmah for help me.

If, the use of pointers to data stored in rom is confused and unclear with ccs Confused
So ask the question in forum Smile
Ttelmah



Joined: 11 Mar 2010
Posts: 19504

View user's profile Send private message

PostPosted: Tue Jul 15, 2014 12:30 am     Reply with quote

Very true.

They have added extra abilities (and in some cases unfortunately 'lost' abilities), with the documentation 'poor'.

The one thing that was a 'cracker', which worked a while ago, then became faulty (haven't yet checked it in 026), was 'addressmod'. This allowed you to use variables in any memory (EEPROM, FLASH, or the internal ROM etc.), and provided you remembered the memories limitations on 'write life', use them as if they were in RAM. Allowed you to have a 'near ROM' type of data which was changed infrequently, and was retained until changed.

CCS have improved a little recently on the overall reliability of the compilers, with fewer 'new bugs' appearing with each release, but still does require you to do some 'juggling' in how you handle things if you are not to generate problems. Pointers give problems even in RAM, if complex types are used (structures inside structures, and go a little 'deep' for example), and declaring an array of pointers, with variable length strings, requires the * syntax in the length parameter, in RAM, and has sometimes been unreliable. KISS, is a good way to work in CCS, even if other designs may look much more elegant, they are more likely to lead to problems....
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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