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 support@ccsinfo.com

String.h functions with const ( ROM) strings?

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



Joined: 15 Mar 2005
Posts: 10

View user's profile Send private message

String.h functions with const ( ROM) strings?
PostPosted: Tue Mar 15, 2005 1:58 pm     Reply with quote

Hi everyone!

I have recently connected my PIC16F84A to a RS232 port and tried outputting various strings/arrays to HyperTerminal.

Many of the variations worked, however i noticed the following problem:

It says in the manual that pointers cannot be created to ROM.
However, (looking at the LIST or .LST file, unless I am making a mistake), many of the string functions
such as strlen, etc.. use pointers.
This makes them unusable with const (ROM) strings.
Since its not a good option to store arrays in RAM, you have to store them in ROM...and that makes string functions not very useful.

Moreover, the compiler doesn't report any problems.

Is there a way to make string.h functions useful with const strings?
I could be misunderstanding something here.

Below is the short program that causes an error during output:
instead of outputting the whole string it only outputs the first letter
because a=strlen(Message); is not assigned the proper value.

Code:
/* Program BEGIN */

#include <16F84A.H>
#include <string.h>

#define RS232_XMIT   PIN_A1
#define RS232_RCV   PIN_A0   // PIC line which receives PC transmission
#fuses XT,NOWDT,NOPROTECT,PUT
#use delay(clock=4000000)   // 4 MHz OSC
#use rs232(baud=9600, xmit=RS232_XMIT, rcv=RS232_RCV)

void main(void)
{
  BYTE i,a, b;

  char const Message[40]="Ohh, that devil mister Wickham!";
  a=strlen(Message);

  while(TRUE)
  {     
     for(i=0;i<=a;i++)   
     {
      b=Message[i];
      putchar(b); 
     }    
    delay_ms(1000); // send string every 1 sec
     
  }
   
}
/* Program END  */
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 2:16 pm     Reply with quote

Use the strcpy() to copy ROM strings into a RAM buffer.
Then you can use the string functions.


char string[50];

void main(void)
{

strcpy(string, "Hello World"); // Copy ROM string to RAM buffer

// Now you can use string.h functions here.

while(1);
}
Pavel Kolinko



Joined: 15 Mar 2005
Posts: 10

View user's profile Send private message

PostPosted: Tue Mar 15, 2005 2:22 pm     Reply with quote

Thanks!
This helps a lot!
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