View previous topic :: View next topic |
Author |
Message |
akaka
Joined: 18 Jul 2012 Posts: 14
|
const char pointer in function |
Posted: Sat Jan 02, 2016 11:25 am |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 02, 2016 12:02 pm |
|
|
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);
}
|
|
|
![](templates/subSilver/images/spacer.gif) |
akaka
Joined: 18 Jul 2012 Posts: 14
|
|
Posted: Sat Jan 02, 2016 12:32 pm |
|
|
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..... |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sat Jan 02, 2016 1:13 pm |
|
|
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 |
|
|
![](templates/subSilver/images/spacer.gif) |
akaka
Joined: 18 Jul 2012 Posts: 14
|
|
Posted: Sat Jan 02, 2016 2:19 pm |
|
|
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!!! |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19369
|
|
Posted: Sat Jan 02, 2016 3:07 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
akaka
Joined: 18 Jul 2012 Posts: 14
|
|
Posted: Mon Jan 04, 2016 4:58 pm |
|
|
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 |
|
![](templates/subSilver/images/spacer.gif) |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Jan 04, 2016 6:31 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
|