CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

to create a pointer to a constant

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
byatin



Joined: 26 Oct 2006
Posts: 10
Location: delhi -india

View user's profile Send private message Send e-mail

to create a pointer to a constant
PostPosted: Tue Nov 07, 2006 1:28 am     Reply with quote

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

View user's profile Send private message

PostPosted: Tue Nov 07, 2006 1:39 am     Reply with quote

Do it this way:
Code:
datawrt("abc");

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.");
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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