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 CCS Technical Support

question about constant string and an array of characters

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



Joined: 13 Jan 2004
Posts: 5

View user's profile Send private message

question about constant string and an array of characters
PostPosted: Tue Jan 13, 2004 8:47 pm     Reply with quote

Thank you for your attention, and I am sorry for my poor English. I am a beginner of CCS and PIC MCU.

I have an funtion as below, whitch is used to drive the LCD. I can't use it to printf constant string. would you help me to solve the problem?

void LCD_Display ( char address_X, char address_Y, char *content )
{
LCD_write_command ( address_X );
LCD_write_command ( address_Y );

while ( *content )
{
LCD_write_data ( *content );
++content;
}

}


It can be used to printf an array of characters, but not to printf constant string. The error message is " Bad expression syntax "

void main ( void )
{
char String[16];
...

LCD_Display ( 0x01, 0x02, String ); //this sentence is OK

LCD_Display ( 0x01, 0x02, "Hello" ); //this can't be compiled

...
}
Mad
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jan 14, 2004 12:30 am     Reply with quote

Quote:
I have a function as below, which is used to drive the LCD.
I can't use it to printf constant string. Would you help me to
solve the problem?


With the CCS compiler you can't pass a pointer to a constant string.
You have to copy the string into a ram buffer first, by using the
special CCS function: strcpy()

In the code below, I have given some examples of other methods
of sending a constant string to the LCD. I have used the functions
in the CCS lcd driver (in LCD.C).

In the first method, I have written a macro, and tried to make it
look like your LCD_Display() function. In the main code I have
two examples of how to call it.

For the 2nd method, I have used a special CCS extension of the
printf() function, to send the output of printf to the lcd_putc function.


Code:
#include <16F877.h>
#fuses XT, NOWDT, NOPROTECT, BROWNOUT, PUT, NOLVP
#use delay(clock = 4000000)
//#use rs232(baud = 9600, xmit=PIN_C6, rcv=PIN_C7, ERRORS)   

#include <lcd.c>

#define LCD_Display(x, y, string)   \
        lcd_gotoxy(x, y);           \
        lcd_putc(string)

//==========================================
void main()
{
char value;

LCD_Display(1, 1, "ABC");

LCD_Display(1, 2, "This is line 2");

value = 0x55;
printf(lcd_putc, "Value = %u \n", value);

while(1);
}


(I'm not at the company right now, so I can't test this code, but
I believe it should work).
LeranCCS



Joined: 13 Jan 2004
Posts: 5

View user's profile Send private message

Thank you, your methods are OK
PostPosted: Wed Jan 14, 2004 9:19 pm     Reply with quote

Smile
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