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

Wrap around memory

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








Wrap around memory
PostPosted: Mon Oct 04, 2004 10:01 pm     Reply with quote

Hello everyone,

I need to implement a "wrap around" access on a 24LC256 memory.
It�s a kind of datalooger, in wich I will always have to read the last 32768
memory positions.
Suppose the logger has saved data until position X. Well, I will have to read, from X-32767 to position X.
Well, I have tried several ways, but nothing. Is there a way I could define a variable just from 0 to 32767 ?

Any help will be appreciated.
Haplo



Joined: 06 Sep 2003
Posts: 659
Location: Sydney, Australia

View user's profile Send private message

PostPosted: Mon Oct 04, 2004 10:10 pm     Reply with quote

Easy:

Code:
int16 Y;

Y++;
if (Y==32768)
    Y=0;


Or even better:

Code:

int16 Y;

Y++;
bit_clear(Y,15);
asmallri



Joined: 12 Aug 2004
Posts: 1635
Location: Perth, Australia

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Mon Oct 04, 2004 10:23 pm     Reply with quote

or

Code:

signed int16 Y;

Y = abs(++y);


or

Code:

int16 Y;

Y = (++Y % 32768);
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