I am trying to pass a String to a function. I have read a lot about RAM/ROM Strings in C18 and my code seems ok but it is not working. My function is like this:
int setBluetoothName (static const rom char *name){
unsigned int n = 0, k = 0;
char string[27] = {0}; // ATNAME + 20 caracteres de nombre + EOF
char command[27] = {0};
_bit state = USART_INT;
// Deshabilito interrupciones del USART
USART_INT_DISABLE;
strcpypgm2ram(&string, &name);
// Numero de caracteres del nombre
for (; string[n] != 0x00 ; ++n);
if(n > 19) return LENGTH_ERROR; // si me pase de 20 letras es muy largo
// Configuro el nombre del Bluetooth
printf("ATNAME%s", &string);
And I use it on this way:
setBluetoothName("Brazo");
In Proteus I see that only the letter 'B' is being passed and when I copy the ROM string to RAM it is simply a mess (see the attached picture). The output of the printf() is only ATNAME, the string is not being printed.
I am woking with C18 v4.40 and MPLABX v1.41. Thank you very much for your help.
Try:
strcpypgm2ram(string, name);
and
printf("ATNAME%s", string);
when you declare an array
char string[27] = {0};
then the variable string refers to the address of the first element of the array, and when you declare a parameter such as
int setBluetoothName (static const rom char *name)
then name refers to the address where the string is located.
When you add an & in from of these, you are getting the address of the variable containing the address of the data.