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

help on custom Send_string_RS232 function
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 1:58 am     Reply with quote

Just tried that, it is working and it's nice.
But it's not what I want; I want to save ROM, what the compiler is, put at compile time the code from the header #define in the program.

In a function you only have call it and the code is only written in ROM once..
Guest








PostPosted: Fri Aug 11, 2006 2:43 am     Reply with quote

'\' means that the code continues onto another line. It stops the line feed 'terminating' the define.
The big problem, is 'inherent' in using constants. Every time you declare a constant, the constant is written into ROM, and _includes_ a 'header', which is the code to access it. So a four character constant, will probably have something like a twenty character header attached. Obviously, you can use a #seperate declaration on putcint, to stop this being repeated, but this still leaves the header present in every constant you define.
One way of dealing with this, is that if all the constants are similar length, to use a constant array to hold the values. So:
Code:

const int8 words_to_send[4][5] = {
    "COMM".
    "Move",
    "Fred",
    "Dick"
};
#define COMMTEXT (0)
#define MOVETEXT (1)
#define FREDTEXT (2)
#define DICKTEXT (3)

Will only have _one_ header.
If you then have your 'call', as:
Code:

#seperate
void myputc(int8 c) {
   putc(c);
}

void Send_String_RS232(int8 stringnum,char y,char z) {
    int8 ctr=0;
    myputc(170);
    do {
        myputc(words_to_send[stringnum][ctr++])
    } while (words_to_send[stringnum][ctr]!=0);
    myputc(y);
    if (y) myputc(z);
}

Then call this with:

Send_Sring_RS232(COMMTEXT,0,0);

(using whichever 'define' you want).

This stores all the constants as a single constant array (with only one 'overhead' then associated)- beware though, that if you are on a 16 chip, the total array size may not exceed 256 characters. Then you use the defined 'access numbers' to select which array line to send, and send all the characters from the line till you get to the end marker. putc, is encapsulated in a 'seperate' function, to avoid CCS putting this 'inline'.
This ought to be abut as small as possible.

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 3:06 am     Reply with quote

Thanks, I will surely test this out.

So actually an ansi C string like "COMM" seems to be 5 bytes?

C O M M 0

When the '0' is seen the loop is exited apparently.
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 3:21 am     Reply with quote

why btw is there that limitation of 256 bytes. A constant table is stored in ROM , isn't it?

It's probably a hardware issue..
Ttelmah
Guest







PostPosted: Fri Aug 11, 2006 5:08 am     Reply with quote

Yes, a four character string, is five bytes. A terminating '\0' is needed to make a 'string'. This is called the 'null terminator' in C.
On the '16' chips, constants are stored using a table of 'RETLW' instructions. The code arrives in front of this table, and the required 'index', is added to the current program counter, to jump into the table. If the table exceeds 256 bytes, there has to be a page switch, which increases the size of the 'header' needed significantly.

Best Wishes
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Fri Aug 11, 2006 5:45 am     Reply with quote

What would be the fastest and shortest way to compare 2 strings?

Code:
const int8 Command_Strings [2][5] = {
    "COM1"
    "COM2"
};


and

Code:
char Temp_Array [4];


Now when receiving characters / commando's from another processor, I need to read them.

How would yo do:

Code:
if ( char Temp_Array [4] == "COM1" )
     return COM1_COMMAND_READ;


Now I'm using:

Code:
// Commando gaan vergelijken met de geprogrammeerde commando's
// Schrijf Braille
   strcpy (command,BRAILLE_COMMANDO);
   if ( !strncmp (temp_array,command,4) )
      return SCHRIJF_NAAR_LEESREGEL;
// Na 30s idlen gaat de E3 in suspend
   strcpy (command,E3_SUSPEND);
   if ( strncmp (temp_array,command,4) == 0 )
   return E3_IN_SUSPEND;
// Batterij commando?
   strcpy (command,BATTERIJ_COMMANDO);
   if ( strncmp (temp_array,command,4) == 0 )
      return VBAT_METEN;


So actually the same code (= waste of rom?) again.

How can this be done with the fewest rom and the fastest way? My gues is that this smells like pointers, however you cannot create pointers to constants I read in the manual..

(my actual goal is to gain as much as free ROM as I'm now at 97%. By doing that I can write a bootloader by which we can flash the PIC via the other processor or PC)
Christophe



Joined: 10 May 2005
Posts: 323
Location: Belgium

View user's profile Send private message

PostPosted: Wed Sep 06, 2006 5:56 am     Reply with quote

anyone?
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Goto page Previous  1, 2
Page 2 of 2

 
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