|
|
View previous topic :: View next topic |
Author |
Message |
Raul Guest
|
const char pointer problem |
Posted: Wed Jan 08, 2003 2:48 pm |
|
|
I'm writing a driver for a custom display which uses a menu system. I defining my text library I decided to use constant character arrays for my text. I then attempt to point to the individual characters for the printing of text. I am using version 3.129 of the compiler and am programming for a PIC18F6720. Here is what I am having problems with.
// In the header file
const char test1[] = "TEST";
void Print_String(const char *ch);
// In function library
void Print_String(const char *ch)
{
int8 x = 0;
while(ch[x] != NULL)
{
w_data = (int)ch[x];
wr_data(); // Sends data to display
x++;
}
}
// Somewhere in code
Print_String(test1);
Now when I try to compile, the compiler stops when it gets to my function declaration, more specifically at the 'char' declaration and I get a message that says 'Expecting a , or )'. I've used this method with a couple other compilers and one being Microchips C17 and it worked fine. Is there a fix or some work around for this?
___________________________
This message was ported from CCS's old forum
Original Post ID: 10543 |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
Re: const char pointer problem |
Posted: Wed Jan 08, 2003 3:08 pm |
|
|
:=I'm writing a driver for a custom display which uses a menu system. I defining my text library I decided to use constant character arrays for my text. I then attempt to point to the individual characters for the printing of text.
------------------------------------------------------
CCS doesn't allow pointers to constant strings.
If you want to pass a pointer, you first have
to copy the string into a ram array by using
the strcpy() function.
But you can still use constant strings.
The following program shows how you could
send the string to an RS-232 terminal, or
to an LCD.
Also, the printf() function can have its
output redirected to another function.
See the manual for info on this.
#include "c:\program files\picc\devices\16F877.h"
#fuses HS,NOWDT,NOPROTECT,PUT,BROWNOUT, NOLVP
#use Delay(clock=8000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)
#include <lcd.c>
const char test1[] = "TEST";
//===============================================
void main()
{
printf(test1);
lcd_putc(test1);
while(1); // Prevent PIC from going to sleep
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10544 |
|
|
johnpcunningham Guest
|
Re: const char pointer problem |
Posted: Wed Jan 08, 2003 3:09 pm |
|
|
This compiler does not allow pointers to constants. You can use an addressing mode to send the characters.
EXAMPLE:
const char line_1[] ="my data";
char i = 0;
while( i != sizeof(line_1)
{
write_data(line_1[i++]);
}
___________________________
This message was ported from CCS's old forum
Original Post ID: 10545 |
|
|
|
|
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
|