|
|
View previous topic :: View next topic |
Author |
Message |
sjharris
Joined: 11 May 2006 Posts: 78
|
Printf routine |
Posted: Fri Jul 18, 2008 7:11 am |
|
|
Hello all,
I have got to a point in my programming where I am writing a lot of printf statements, this is obviously using a lot of ROM and RAM.
I have now put the printf statement in a routine and i am passing the routine the string to print.
But I have a problem with passing the routine a string, i.e. the compiler doesnt like
Code: |
void send_serial(serial_string)
{
puts(serial_string);
}
.
.
.
.
send_serial("This is a test string"); |
Error "Attempt to create a pointer to a constant"
So I am forced to use:-
Code: |
void send_serial(serial_string)
{
puts(serial_string);
}
.
.
.
.
strcpy(serial_string, "This is a test string");
send_serial(serial_string);
|
My question is, would this save code space in the long run or is there another way of sending a string to a function?
TIA
sjharris |
|
|
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Fri Jul 18, 2008 8:11 am |
|
|
To answer your question, No I don't think this will save code space in the long run. I believe that printf stores the strings in program memory. You could try to store them in the DATA EEPROM of the chip to save program memory.
In the old compilers 3.2xx you could just make a function that takes a char
and then when using the function, pass it a string. And the compiler does the
magic to call the function for every letter of the string.
Code: |
void send_serial(char a)
{
putc(a);
}
.
.
.
.
send_serial("This is a test string");
|
see C:\Program Files\PICC\Drivers\LCD.C
C:\Program Files\PICC\Examples\EX_LCDKB.C
Quote: | lcd_putc("\fReady...\n"); |
If there is formatting involved then use printf with a custom function.
see ccsc.chm fprintf/printf
printf(fname, cstring, values...) where fname is a function name to be used for outputting a single char |
|
|
|
|
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
|