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

Store and print string-constants

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







Store and print string-constants
PostPosted: Tue Jun 03, 2003 8:33 am     Reply with quote

There was already a discussion in the past, but I couldn?t
find it in the archive.

Question:
printf("string_constant1")
printf("string_constant2")
uses too much rom.

What is the best methode to print constant strings without
too much rom usage?

Thanks TED
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515004
Steve H.
Guest







Re: Store and print sting-constants
PostPosted: Tue Jun 03, 2003 9:36 am     Reply with quote

I searched "String Rom" for 300 days back.

See the link...
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515005
R.J.Hamlett
Guest







Re: Store and print sting-constants
PostPosted: Tue Jun 03, 2003 3:21 pm     Reply with quote

:=I searched "String Rom" for 300 days back.
:=
:=See the link...


Also, if the chip is one of the 18x family (where individual instruction memory locations can store two bytes), this code becomes unecessary, _but_ you can still save space quite massively by putting several messages into one table.
Something like:

const large_message[] = "Message1\000Message2\000Message3";
#define MESSAGE1 0
#define MESSAGE2 9
#define MESSAGE3 18

void mprint(int address) {
while (large_message[address] != '\000') {
putc(large_message[address++]);
}
}

Then you can call the function as:

mprint(MESSAGE1);

I use a very similar arrangement in my own code, with four seperate message tables, for different languages, then the 'mprint' routine, selects the right table according to the selected language, and the correct message is then printed from this.
As written the code will only work for short tables (remember the limits on the size of an integer), but it is fairly easy to extend this is needed.

This saves space, because the compiler has to generate a table 'setup' routine, for each seperate constant string. This can be as long as the string, for short messages. By combining all the messages into larger strings, you reduce the number of such 'setup' overheads generated.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515018
Ted
Guest







Re: Store and print sting-constants
PostPosted: Wed Jun 04, 2003 12:39 pm     Reply with quote

Thanks for the link. The program stores two chars in a 14bit
rom place.
Originally it is used for eeprom storage and with read_eeprom()
the rom contents is readed.

I´ve a 16F76 and want to store strings in (program)-rom.
Storing a 14bit constant is possible, but how to read?

Any idea?

Regards Ted
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515035
Steve H.
Guest







That's about all I know...
PostPosted: Wed Jun 04, 2003 1:52 pm     Reply with quote

That's about all I know, it's annoying for us all. Either hand code some packing scheme or use external EEPROM. Danged if you do or danged if you don't.

In the past I've searched the board for ideas then used them as the basis for some third scheme that just barely works for the situation I'm in. When all else fails I've moved up a chip in memory size....

Best of luck,

Steve H.
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515036
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

Re: Store and print sting-constants
PostPosted: Thu Jun 05, 2003 9:21 am     Reply with quote

:=:=I searched "String Rom" for 300 days back.
:=:=
:=:=See the link...
:=
:=
:=Also, if the chip is one of the 18x family (where individual instruction memory locations can store two bytes), this code becomes unecessary, _but_ you can still save space quite massively by putting several messages into one table.
:=Something like:
:=
:=const large_message[] = "Message1\000Message2\000Message3";
:=#define MESSAGE1 0
:=#define MESSAGE2 9
:=#define MESSAGE3 18
:=
:=void mprint(int address) {
:= while (large_message[address] != '\000') {
:= putc(large_message[address++]);
:= }
:=}
:=
:=Then you can call the function as:
:=
:=mprint(MESSAGE1);
:=
:=I use a very similar arrangement in my own code, with four seperate message tables, for different languages, then the 'mprint' routine, selects the right table according to the selected language, and the correct message is then printed from this.
:=As written the code will only work for short tables (remember the limits on the size of an integer), but it is fairly easy to extend this is needed.
:=
:=This saves space, because the compiler has to generate a table 'setup' routine, for each seperate constant string. This can be as long as the string, for short messages. By combining all the messages into larger strings, you reduce the number of such 'setup' overheads generated.
:=
:=Best Wishes

Taking this one step further you can use an index for delimited messages within a constant string. This is only usefull if the constant string is longer than 256 bytes. You can buy a package of software and toutorials from Peter Anderson that includes an example of this for use with CCS

<a href="http://www.phanderson.com/" TARGET="_blank">http://www.phanderson.com/</a>
___________________________
This message was ported from CCS's old forum
Original Post ID: 144515050
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