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

How can I use const data commands with printf

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



Joined: 21 Jan 2007
Posts: 5

View user's profile Send private message

How can I use const data commands with printf
PostPosted: Sun Jan 21, 2007 9:06 am     Reply with quote

I have a problem to access data with the new const data commands:
1. I declare constant data in programm memory and want to put it out with printf.
const char Menu1[][*]={"Pretrigger","Posttrigger","Sequence","One shoot"};
How can I access data to put it out to an LCD Display.
printf(lcd_put,"%s", Menu1[1]);
this doesn't work )

2. The same problem with:
char ROM commands[] = {"Pin|Port|RS232|V24"};
printf (lcd_put,"%s",commands[1]);
this doesn't work.

Has anybody used these commands?
_________________
Helmut Strasser
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Sun Jan 21, 2007 9:27 am     Reply with quote

If you are using version 3.x and below, it doesn't support pointers to constants.
strasserh



Joined: 21 Jan 2007
Posts: 5

View user's profile Send private message

constant data
PostPosted: Sun Jan 21, 2007 11:46 am     Reply with quote

I use Version 4.021, and it is no problem to compile, but it doesn't work.
thx
_________________
Helmut Strasser
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Sun Jan 21, 2007 4:03 pm     Reply with quote

Hi,

I've only got versoin 3.xxx so I can't comment, if there are any changes in v4 that make what I'm about to say in-correct.

I understand (could be wrong) that PICs can't reference the ROM as pointers, you have to copy the constant character strings to RAM. I don't know if this is a CCS thing or a PIC thing.

I use something like this in all my "human interface/menu" programs.

Code:

//==========================================================================
//==========================================================================
// STRING CONSTANTS
//==========================================================================
//==========================================================================
char STRstart[6];
char STRstop[5];
char STRshelp[6];
char STRset_[5];
char STRpwm_[5];
void str_init()
{
  strcpy(STRstart,"start");
  strcpy(STRstop,"stop");
  strcpy(STRshelp,"shelp");
  strcpy(STRset_,"set ");
  strcpy(STRpwm_,"pwm ");
}
//==========================================================================
//==========================================================================
// END - STRING CONSTANTS
//==========================================================================
//==========================================================================



These variables are now stored in RAM, and can then be used as pointers in functions like printf.

Have a check of the manual for a fuller explanation.

Cheers Scott
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Jan 21, 2007 5:06 pm     Reply with quote

If you initialize the RAM arrays like this, it will use far less ROM space.
Code:

char STRstart[6]= {"start"};
char STRstop[5] = {"stop"};
char STRshelp[6] = {"shelp"};
char STRset_[5] = {"set"};
char STRpwm_[5] = {"pwm"};
ferrumvir



Joined: 01 Feb 2006
Posts: 64
Location: England

View user's profile Send private message Visit poster's website

PostPosted: Mon Jan 22, 2007 1:58 am     Reply with quote

Thanks PMC_Programmer,

That's very useful to know, as I've only ever got close to the ROM limit when programming menus for hyperterminal.

Cheers Scott
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

Re: How can I use const data commands with printf
PostPosted: Mon Jan 22, 2007 6:02 am     Reply with quote

strasserh wrote:
I have a problem to access data with the new const data commands:
1. I declare constant data in programm memory and want to put it out with printf.
const char Menu1[][*]={"Pretrigger","Posttrigger","Sequence","One shoot"};
How can I access data to put it out to an LCD Display.
printf(lcd_put,"%s", Menu1[1]);
this doesn't work )

2. The same problem with:
char ROM commands[] = {"Pin|Port|RS232|V24"};
printf (lcd_put,"%s",commands[1]);
this doesn't work.

Has anybody used these commands?

Normally you would declare like this:
const char* Menu1[]={"Pretrigger","Posttrigger","Sequence","One shoot"};
strasserh



Joined: 21 Jan 2007
Posts: 5

View user's profile Send private message

is it a CCS bug or not, thats the question
PostPosted: Mon Jan 22, 2007 3:08 pm     Reply with quote

Hi Mark!
Yes I thought like you did, but the CCS compiler didn't accept this syntax.

And if you use the original syntax it doesn't work, or I am too dumb to use it.
_________________
Helmut Strasser
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 22, 2007 3:25 pm     Reply with quote

Mark is thinking of the C18 compiler.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

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

PostPosted: Mon Jan 22, 2007 3:42 pm     Reply with quote

PCM programmer wrote:
Mark is thinking of the C18 compiler.

Nope, this works for GNU for ARM as well as CodeWarrior for Freescale MCU's. I am currently developing code for both and this is how I would declare them. C18 is a little different in that you specify the rom qualifier. I don't know how CCS's version 4 of the compiler works, but if it allows pointers to constants, it should be something like this.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 22, 2007 5:11 pm     Reply with quote

To get back to answering the original question, about how to use 'const'
data with printf, see the example code in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=25483
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Tue Jan 23, 2007 8:59 am     Reply with quote

I do something like this.
This is only 1 line, 2,3,4 is just the same.
Its a 2d array, so all lines must be the same length.(16that is 15 and null termination)
int8 ERRORS; //is a global bit map, set bit 0 and it will show buffer overflow.
Code:
const char error_txt[1][16] =
{
   "buffer overflow"  // -0-
//"buffer overflow",  // -0-
//" ",// -1-
//" ",// -2-
//" ",// -3-
//" ",// -4-
//" ",// -5-
//" ",// -6-
//" "
};
//========================== err_chk ===============================
void ChkErr(void) //print out any errors that occured
//**verifly that error text is applicable
{
   int8 chk=0;
   if (ERRORS==0){return;} //if no errors jump right back out
   for(chk=0;chk<8;chk++)
   {
      if (bit_test(ERRORS,chk))
      {
         bit_clear(ERRORS,chk);
         fprintf(DEBUG,"ERROR(%U): %s.\r\n",chk,error_txt[chk]);
         rx_indx_i=rx_indx_o=0;
      }
   }
}
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