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

function call problem

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



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

function call problem
PostPosted: Thu Dec 21, 2006 11:02 am     Reply with quote

Hi guys,

I'm having a small problem with function calls. Please see the code and explaination below:

This code works
----------------------------
void main(void){
...
lcd_putc("lcd1");
}

void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1);
delay_ms(2);
break;

case '\n':
lcd_gotoxy(1,2);
break;

case '\b':
lcd_send_byte(0,0x10);
break;

default:
lcd_send_byte(1,c);
break;
}
}
--------------------------

The code below gives me a "Attempt to create a pointer to a constant
" error, please help. The only difference being the extra variable in the function call.

void main(void){
...
lcd_putc("lcd1", 1); <-- error here
}

void lcd_putc(char c, int lcdNum)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1, lcdNum);
delay_ms(2);
break;

case '\n':
lcd_gotoxy(1,2, lcdNum);
break;

case '\b':
lcd_send_byte(0,0x10, lcdNum);
break;

default:
lcd_send_byte(1,c, lcdNum);
break;
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 12:10 pm     Reply with quote

You're trying to re-write the lcd_putc() function to allow use with
multiple LCDs.

CCS has a special feature in which you can pass a constant string
to a function and it will do multiple calls of the function, one for each
byte in the string. That feature only works if the function has only
one parameter, and the parameter is a byte. That's why your code
fails to compile.

One solution for your problem is just to use a global variable to
set the LCD number.
Then you can keep the lcd_putc() function in the single parameter
form, and you can give it a constant string.
Joseph88



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 12:18 pm     Reply with quote

Will the global variable work if the putc function is in a different file?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 12:20 pm     Reply with quote

Yes, it would.
Joseph88



Joined: 14 Aug 2006
Posts: 17

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 12:47 pm     Reply with quote

From the CCS Manual, to create a global variable, you use the #MODULE command. Everything before the #MODULE is considered global correct?

This is what i've done below. Should the lcdNum variable be global? I'm getting an "Undefined identifier lcdNum" in my FlexLCD.c file in lcd_putc.

#include <18f4525.h>
#use delay(clock=8000000, int)
#fuses NOWDT, NOLVP
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7, PARITY=N)

#include < FlexLCD.c >
int lcdNum;
#MODULE

void main(void)
{
lcdNum=1;
lcd_init(lcdNum);
lcd_putc("lcd1");
}

void lcd_putc(char c)
{
switch(c)
{
case '\f':
lcd_send_byte(0,1, lcdNum);
delay_ms(2);
break;

case '\n':
lcd_gotoxy(1,2, lcdNum);
break;

case '\b':
lcd_send_byte(0,0x10, lcdNum);
break;

default:
lcd_send_byte(1,c, lcdNum);
break;
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Dec 21, 2006 1:00 pm     Reply with quote

Forget the #module directive. Just stick the global immediately above
your #include statement for the LCD driver.
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