Pavel Kolinko
Joined: 15 Mar 2005 Posts: 10
|
String.h functions with const ( ROM) strings? |
Posted: Tue Mar 15, 2005 1:58 pm |
|
|
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 */ |
|
|