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

const char pointer in function

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



Joined: 18 Jul 2012
Posts: 14

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

const char pointer in function
PostPosted: Sat Jan 02, 2016 11:25 am     Reply with quote

Hi all,
I am searching 2 days in the forum but I haven't found any solution about this.

I have version 5.015 and 16f877a mcu and I am facing problem in ccs compiler. Here is a sample code with my function:
Code:
void PutStrD(BYTE nX, BYTE nY,const char *s);//function prototype

PutStrD(0,0,"Hello");


P.S. rom keyword instead of const is not working properly

Is there any solution to use const char *(pointers) as function parameter???
Thanks in advance
Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 02, 2016 12:02 pm     Reply with quote

I was able to get your code to compile and run with vs. 5.015, by adding
the two lines shown below in bold:
Quote:

#include <16F1847.H>
#device ANSI
#device PASS_STRINGS=IN_RAM

#fuses INTRC_IO, NOWDT, BORV25
#use delay(clock=8M)
#use rs232(baud=9600, UART1, ERRORS)

void PutStrD(BYTE nX, BYTE nY,const char *s); //function prototype


void PutStrD(BYTE nX, BYTE nY, const char *s)
{

printf(s);

}

//==========================
void main()
{
PutStrD(0,0,"Hello");

while(TRUE);

}
akaka



Joined: 18 Jul 2012
Posts: 14

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

PostPosted: Sat Jan 02, 2016 12:32 pm     Reply with quote

Hi PCM programmer,
Thank you for your quick response.
I have tried this before but it the compiler shows : Data item too big...
I have a conversion table of 256 bytes and is too big I think so.
Here is a small project https://www.sendspace.com/file/hs1lcv

if you could help.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat Jan 02, 2016 1:13 pm     Reply with quote

I got it to compile with these changes, as shown in bold below:
Quote:
#include <16F877A.h>
//#device ANSI
#device PASS_STRINGS=IN_RAM
#fuses HS,NOWDT,NOPROTECT,NOBROWNOUT,NOLVP,NOPUT,NOWRT,NODEBUG,NOCPD
#use delay (clock=8000000)
//#device CONST=ROM

and
Quote:
void GotoXY(BYTE nX, BYTE nY);
void ClrDspl(void);
void ClrToEOL(BYTE nX, BYTE nY);
void ClrToEOD(BYTE nX, BYTE nY);
void PutAttrD(BYTE nX, BYTE nY, BYTE nAttr, BYTE nLen);
void SetAttr(BYTE nAttr);
void PutChD(BYTE nX, BYTE nY, BYTE ch);
void PutStrD(BYTE nX, BYTE nY,char *s); // *** REMOVED 'const'
void PutCh(BYTE ch);
void PutStr(char *s); // *** REMOVED 'const'
BYTE SetCursor(BYTE nFlag);
void SaveScreen(BYTE *pScr);
void RestoreScreen(BYTE *pScr);
//void TurnBackLightOn(void);
//void TurnBackLightOff(void);

and
Quote:

void PutStrD(BYTE nX, BYTE nY, char *s) // *** REMOVED 'const'
{
BYTE i;


for (i=nX; i<DSPL_COLS && *s; ++i, ++s) {
aDisplay[0][i][nY] = *s;
if (nDAttr!=DATTR_NONE)
aDisplay[1][i][nY] = nDAttr;
} // for
if (nX<aDRefr0[nY])
aDRefr0[nY] = nX;
} // PutStrD

and
Quote:

void PutStr(char *s) // *** REMOVED 'const'
{
while (*s) {
PutCh(*s);
++s;
} // while
} // PutStr
akaka



Joined: 18 Jul 2012
Posts: 14

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

PostPosted: Sat Jan 02, 2016 2:19 pm     Reply with quote

Thank you PCM programmer,
if you see i my history I have tried directive #device PASS_STRINGS=IN_RAM but without removing const.
It's working!!!!
Now this way I can move some libraries to ccs compiler.

1.000.000 thank you and happy new year!!!
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Sat Jan 02, 2016 3:07 pm     Reply with quote

The point about the 'pass strings' option, is that it creates a 'virtual' RAM pointer to the table, so is then useable as if it is in RAM. Hence the pointers have to be to RAM.

The ROM option instead allows a ROM pointer to be constructed, but was dubious on your compiler (they got it working properly in the mid 5.02x versions). 5.015, is an 'early' working V5 compiler, and still had some problems.
akaka



Joined: 18 Jul 2012
Posts: 14

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

PostPosted: Mon Jan 04, 2016 4:58 pm     Reply with quote

Hi PCM programmer,

I have tried to make my previous project as a multiple compilation unit and some times it is shown a message about an internal hidden error and some times *** Error 129 "library_test.c" Line 4(8,14): File can not be opened for write...---> this file contains the import directives.
here is the uploaded almost the same project
https://www.sendspace.com/file/ibfxh9

Thanks in advance

Chris
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 04, 2016 6:31 pm     Reply with quote

akaka wrote:

I have tried to make my previous project as a multiple compilation unit

I don't have the full IDE version of the compiler, so I can't test multiple
compilation units. I only have the command line compilers, PCM & PCH.
Maybe somebody else who has the full IDE can help you.
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