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

Searching Buffers and comparing to characters NOT IN RAM
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
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 1:47 pm     Reply with quote

better said

can i adress a single character on that

Const char strA[]="ABC";


as in the if statement:

if(strA[1]=='B')
{
}


if that is possible... all is well...

i have no problem coding For loops hahahha


g
_________________
CCS PCM 5.078 & CCS PCH 5.093
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 1:58 pm     Reply with quote

I'm sure you could code the function yourself. But the 18 series has a huge amount of RAM, I copy large arrays to RAM which, if you reference a lot, saves both processor time and ROM space. Are you sure you don't have room to copy some strings to RAM and make this simple?
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Wed Aug 12, 2009 2:01 pm     Reply with quote

Gabriel wrote:
better said

can i adress a single character on that

Const char strA[]="ABC";


as in the if statement:

if(strA[1]=='B')
{
}


if that is possible... all is well...



g


I made a little test program:

Code:


#include <18F252.h>
#fuses XT, NOWDT, PUT, BROWNOUT, NOLVP
#use delay(clock=4000000)

const char abc[] = "ABCDEFG";
char result=99;


void main()
{

if (ABC[0] == 'A') result = 1;
else result = 0;


delay_ms(1); //BREAKPOINT HERE

}


And if you use WATCH in MPLAB SIM you see that result = 1. So I guess if you want to do it that way it'll work.

But mskala is right...The 18 series does have an exorbitant amount of RAM, so much so that it's always ROM that I run out of long before I run out of RAM.
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 2:14 pm     Reply with quote

mkuang...

I'm back to loving you hahahahah


18 series... yeah sure....

but ehmm , I'm using 16f877A...

thanks for the test code....

I'm at the office right now.. far away from any compiler... for several hours

to come...

thank you

g
_________________
CCS PCM 5.078 & CCS PCH 5.093
mskala



Joined: 06 Mar 2007
Posts: 100
Location: Massachusetts, USA

View user's profile Send private message

PostPosted: Wed Aug 12, 2009 5:53 pm     Reply with quote

sorry remembering different thread. Although once you buy the compiler
the 18f4550 is cheaper than 16f877a and is far superior.

Nevertheless, you have 368 bytes to work with. How much string do you
have to accept? Just check more often and get rid of the stuff you
already checked if it is a long string.
Wayne_



Joined: 10 Oct 2007
Posts: 681

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 3:15 am     Reply with quote

You can do something like :-

Code:


#define MAXTABLE 4

char buf[50];
const char table[MAXTABLE][10] = {"first", "second", "third", "forth"};

void main()
{
  char tmpStr[10];
  int n;
  bool found;

  strcpy(buf, "my first string");
 
  for (n = 0; n <  MAXTABLE; n++)
  {
    strcpy(tmpStr, table[n]);  // Copy the string to ram
    if (strstr(buf, tmpStr) != null)  // Look for tmpStr in buf
      break;
  }
  if (n != MAXTABLE)
    found = true;
  else
    found = false;
}


Note I did say LIKE as I have not tested this but I am sure with a little tweaking it will do what you want!
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 6:52 am     Reply with quote

hey all,

i got it working quite nicely using the

const char Str[].... (this was exactly what i wanted)
and a forloop. not an ounce of RAM increase. SWEET.

now, i was wondering what is the diference between

const char Str[] and an ENUM data type?.... when i got home from work i started looking for more options....




about the runing out or ram issue... im on the initial stages of my project and i am already at 50-52% RAM usage...
this is mostly because i have a Buffer of 70 chars...

ive seen what my GSM module sends to the PIC , and its a lot of text, depending on what type of command you send or if you actually have to read a full text msg ... it can be quite extensive...

but i think i will handle everything in 30 char snapshots... reading multiple times a sms ...

the thing is, i have to manage to handle all the GSM comunication, with as little ram as possible since my project WILL have to do some data proscesing. math related almost entierly... and also i will be using the ADC @ 10 bit resolution... which might result in some 32 bit math...
I NEED to save ram now so that when i get to that part of my project i have some left...


anyways... the what was discussed on this thread worked nicely...

and if when i finish, i have a whole lot of ram left, then i will have one memory efficient piece of software!


thank you all for your help...

Gabriel
_________________
CCS PCM 5.078 & CCS PCH 5.093
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Thu Aug 13, 2009 8:37 am     Reply with quote

Gabriel wrote:
hey all,

now, i was wondering what is the diference between

const char Str[] and an ENUM data type?....


A const char str[] is just that, a list of numbers and/or ascii characters stored in a fixed placed in your hex file (or ROM if you preferred). You cannot change or modify it any more than you can modify your hex file.

An ENUM is short for an enumeration. Lets say I want to do something like:

Code:

#define APPLE 1
#define GRAPE 2
#define ORANGE 3
#define MELON   4
#define BANANA 5



An easier way of doing this would be to do:


Code:

enum{APPLE = 1, GRAPE, ORANGE, MELON, BANANA};



The reserved word enum will tell the compiler to automatically increment each element of the array. You can do APPLE = ANY number you want and the compiler will increment each subsequent element of the array accordingly. Incidentally if you just do:
Code:


enum{APPLE, GRAPE, ORANGE, MELON, BANANA};



then APPLE will equal to zero, grape equals one, etc..

Enum is a constant array and is thus in ROM.
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 10:35 am     Reply with quote

so in :

Code:
enum{APPLE, GRAPE, ORANGE, MELON, BANANA};


how do i address the objects inside the enum?

i am asumming the proper declaration is:

Code:

Enum TABLE{APPLE, GRAPE, ORANGE, MELON, BANANA}


table bien the name of the enum....


like: TABLE[0] == "APPLE" ? is that a proper way to address objects enumerated?


cound i do: strcmp("APPLE", Enum[0]); ???

i get the idea of the Enum, but i dont get whats its practical aplication when basically a const char will do just that...

the only diference i see is that the "index" number in an Enum can be fixed by the user...

i just want to understand this correctly so that if Enum is a "better" data type for my project, i can adjust and change to Enum instead.

const char IS working for me right now... i wrote the code and it was perfect.


thanks for your help

g[/code]
_________________
CCS PCM 5.078 & CCS PCH 5.093
mkuang



Joined: 14 Dec 2007
Posts: 257

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

PostPosted: Thu Aug 13, 2009 10:45 am     Reply with quote

I think you are missing a bit of the point. An enumeration is for readability. It's purpose is to replace a bunch of #define statements. There is no "name" associated with an enumeration like what you are trying to do here:


Code:

Enum TABLE{APPLE, GRAPE, ORANGE, MELON, BANANA}


You can try it but you probably are going to get a compiler error. There is thus no "index" to an enumeration.

For your application just declare a constant character array and ditch the enumeration.
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 1:32 pm     Reply with quote

i guess the reason why i am missing the point is because never

used the #define .... no knowledge on its use or purpose ...

i guess i got some reading to do... sugestions on where to read?

besides the help tab on the compiler?


i am already using the const char.... i implemented it last night as soon as i got home from work.


G
_________________
CCS PCM 5.078 & CCS PCH 5.093
Gabriel



Joined: 03 Aug 2009
Posts: 1085
Location: Panama

View user's profile Send private message

PostPosted: Thu Aug 13, 2009 1:39 pm     Reply with quote

i got it... i got it...

never mind...

thanks mkuang

g
_________________
CCS PCM 5.078 & CCS PCH 5.093
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