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 *Dia[]={"X","Mon","Tus&q

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



Joined: 20 Aug 2004
Posts: 2

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

const char *Dia[]={"X","Mon","Tus&q
PostPosted: Fri Aug 20, 2004 3:14 am     Reply with quote

Dear all,


I am trying CCS C compiler. I allways have been working with Hi-tech.

I need to define a constant table of strings for Week days.

Does anybody knows if it is possible in CSS Pic Complier


Code:
const char *Dia[]={"X","Lun","Mar","Mie","Jue","Vie","Sab","Dom"};
const char *Mes[]={"X","Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"};   

  printf("F:%2d/%3s/%2d _%3s", month_day,Mes[month],year, Dia[week_day]);



If not, any other possibility ???


Thanks in advance.


NOTE: Sorry my English
email: eb7dzp@hotmail.com
Ttelmah
Guest







Re: const char *Dia[]={"X","Mon","T
PostPosted: Fri Aug 20, 2004 7:31 am     Reply with quote

eb7dzp wrote:
Dear all,


I am trying CCS C compiler. I allways have been working with Hi-tech.

I need to define a constant table of strings for Week days.

Does anybody knows if it is possible in CSS Pic Complier


Code:
const char *Dia[]={"X","Lun","Mar","Mie","Jue","Vie","Sab","Dom"};
const char *Mes[]={"X","Ene","Feb","Mar","Abr","May","Jun","Jul","Ago","Sep","Oct","Nov","Dic"};   

  printf("F:%2d/%3s/%2d _%3s", month_day,Mes[month],year, Dia[week_day]);



If not, any other possibility ???


Thanks in advance.


NOTE: Sorry my English
email: eb7dzp@hotmail.com

The simple answer, is 'no'.
CCS, does not allow pointers to data in ROM (which a const is).
You have a number of choices:
1) Remove the 'const' declaration, and the data will automatically be copied to RAM on initialisation, and the code will work.
2) Declare the data as a two dimensional array (rather than an array of pointers), and use your own routine to step through the output strings.
3) Take advantage of the CCS shortcut, where if a constant string like this is presented to a routine that accepts single character input, the compiler will automatically 'walk through' the string to send it a character at a time.
It does slightly speed the code, but is an area where CCS, has lagged Hi-Tech for a long time, and been the cause of significant annoyance at times...

Best Wishes
treitmey



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

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

PostPosted: Fri Aug 20, 2004 8:33 am     Reply with quote

I do a simular thing with a 2d array.
Code:

const char error_txt[16][16] =
{
  "USART overflow",  // -0-
  "TXBuffer ovrflw", // -1-
  "RXBuffer ovrflw", // -2-
};




Code:
      fprintf(STDERR,"ERROR(%U): %s.\r\n",chk,error_txt[chk]);
eb7dzp



Joined: 20 Aug 2004
Posts: 2

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

One Solution but not the best.
PostPosted: Fri Aug 20, 2004 9:52 am     Reply with quote

Thanks for your answer.


At the end, I prefered this one:

Code:
const char fecha_hora_txt[21][4] =
{
   "X",
   "Lun",
   "Mar",
   "Mie",
   "Jue",
   "Vie",
   "Sab",
   "Dom",
   "X",
   "Ene",
   "Feb",
   "Mar",
   "Abr",
   "May",
   "Jun",
   "Jul",
   "Ago",
   "Sep",
   "Oct",
   "Nov",
   "Dic"
};


I donīt know why CCS, does not allow pointers to data in ROM, itīs a pitty.


So, thanks once again.


Best regards.
Ttelmah
Guest







Re: One Solution but not the best.
PostPosted: Fri Aug 20, 2004 11:01 am     Reply with quote

eb7dzp wrote:
Thanks for your answer.


At the end, I prefered this one:

Code:
const char fecha_hora_txt[21][4] =
{
   "X",
   "Lun",
   "Mar",
   "Mie",
   "Jue",
   "Vie",
   "Sab",
   "Dom",
   "X",
   "Ene",
   "Feb",
   "Mar",
   "Abr",
   "May",
   "Jun",
   "Jul",
   "Ago",
   "Sep",
   "Oct",
   "Nov",
   "Dic"
};


I donīt know why CCS, does not allow pointers to data in ROM, itīs a pitty.


So, thanks once again.


Best regards.

Yes.
It 'makes sense', in two contexts. The first is that with older chips, where this memory cannot be accessed, except by using the 'RETLW' function, a 'pointer', involved a lot of overhead. This disappeared with chips having the table read functions.
The second, is that it implies that a memory 'pointer', has to be large enough, to cover both the ROM space, and the RAM space, implying (for instance), on a 18Fxx20 part, a size of 21bits to cover the possible ROM space, plus another bit to include the RAM space. Conversely, the entire RAM space on the largest chips, can still be covered with only about a 12bit pointer. This has significant implications in speed, and code size.
That being said, there should (to my mind), be an option on the chips supporting the table read operations, similar to the *=16 option, allowing large pointers, and support for ROM access...

Best Wishes
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