View previous topic :: View next topic |
Author |
Message |
byatin
Joined: 26 Oct 2006 Posts: 10 Location: delhi -india
|
to create a pointer to a constant |
Posted: Tue Nov 07, 2006 1:28 am |
|
|
hi friends ,i am designing an lcd driver but a i am getting a small error in the following code ,the error is
ERROR: Attempt to create a pointer to a constant
ON THE LINE
----- display_on_lcd("abc",3); //THIS IS IN MAIN.
and it's defination is-:
void display_on_lcd(unsigned char * dis_data,unsigned char length)
{
unsigned char i;
for(i = 0; i<length; i++)
{
datawrt(dis_data[i]);
}
}
void datawrt(unsigned char x)
{
busy();
set_tris_d(0x00); //making port d as an output port
output_d(x);
output_high(lcd_rs);
output_low(lcd_rw);
output_high(lcd_en);
delay_us(1);
output_low(lcd_en);
}
can anybody help me in this error as i have to display a string on the lcd. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Tue Nov 07, 2006 1:39 am |
|
|
Do it this way:
The compiler will send the characters in the string, one at a time,
to the datawrt() function. It will send 'a', then 'b', and then 'c'.
The LCD will display 'abc'. Don't use the display_on_lcd() function.
The CCS manual says:
Quote: |
A (non-standard) feature has been added to the compiler to help
get around the problems created by the fact that pointers cannot
be created to constant strings.
A function that has one CHAR parameter will accept a constant
string where it is called. The compiler will generate a loop that will
call the function once for each character in the string.
Example:
void lcd_putc(char c )
{
...
}
lcd_putc ("Hi There."); |
|
|
|
|