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

Convert search string that points to a constant into CCS

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



Joined: 19 Jul 2007
Posts: 9

View user's profile Send private message

Convert search string that points to a constant into CCS
PostPosted: Mon Dec 26, 2011 1:42 am     Reply with quote

Hi, below is AVR code, but I got problem to modify into CCS code.
The problem is this line, I don't know how to convert, can anyone help?
Code:

const unsigned char *searchStrings[4] = {OK, CMTI, READY, CR_LF};   //!< Initialize pointer


Code:

//! Possible strings pointed to by searchStr
const unsigned char OK[]    = "OK\r\n";   //!< "OK"
const unsigned char CMTI[]  = "+CMTI: ";  //!< New Message arrived
const unsigned char READY[] = "> ";       //!< Phone ready to receive text message
const unsigned char CR_LF[] = "\r\n";     //!< Carrige Return Line Feed
const unsigned char *searchFor;                     //!< Flash pointer
const unsigned char *searchStrings[4] = {OK, CMTI, READY, CR_LF};   //!< Initialize pointer


void COM_setSearchString( unsigned char Response )
{
disable_interrupts(INT_RDA);//UCSR0B &= ~( 1 << RXCIE0 );  // Disable RX interrupt
searchFor = searchStrings[Response];  //Set desired search dtring
searchStr = Response;                 //Used in rx_isr
rx_i = 0;
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19346

View user's profile Send private message

PostPosted: Mon Dec 26, 2011 7:41 am     Reply with quote

Several bits to this.
First 'const', on the AVR, has a different meaning to 'const' on the PIC. On the PIC, a 'const' is stored in ROM, (unless you select 'ANSI' mode). On the AVR (or the PIC if you select ANSI), a 'const' is just a variable that cannot be written.
Now the default 'const' constructor in CCS, doesn't support pointers (this is down to just how hard (imposssible...) pointers to ROM were on the earliest PICs. On latter PICs you can have pointers to ROM, using the 'ROM' constructor, rather than 'const'.
However in all cases, CCS does not support compile time initialisation.

So realistically, the easiest construction, is:
Code:

unsigned char *searchStrings[4];
//! Possible strings pointed to by searchStr
unsigned char OK[]    = "OK\r\n";   //!< "OK"
unsigned char CMTI[]  = "+CMTI: ";  //!< New Message arrived
unsigned char READY[] = "> ";       //!< Phone ready to receive text message
unsigned char CR_LF[] = "\r\n";     //!< Carrige Return Line Feed
unsigned char *searchFor;                     //!< Flash pointer

//Then at some point in your early code in the main:
searchStrings[0] = OK;
searchStrings[1] = CMTI;
searchStrings[2] = READY;
searchStrings[3] = CR_LF;   //!< Initialize pointer


It is also possible to use ROM for the actual string declarations, which will save RAM, but make the code a little larger.

Best Wishes
kutkm_ti



Joined: 19 Jul 2007
Posts: 9

View user's profile Send private message

PostPosted: Mon Dec 26, 2011 10:07 pm     Reply with quote

thank you very much, now i can compile my own code!
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