View previous topic :: View next topic |
Author |
Message |
Guest
|
Wrap around memory |
Posted: Mon Oct 04, 2004 10:01 pm |
|
|
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. |
|
![](templates/subSilver/images/spacer.gif) |
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Mon Oct 04, 2004 10:10 pm |
|
|
Easy:
Code: | int16 Y;
Y++;
if (Y==32768)
Y=0; |
Or even better:
Code: |
int16 Y;
Y++;
bit_clear(Y,15);
|
|
|
![](templates/subSilver/images/spacer.gif) |
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Mon Oct 04, 2004 10:23 pm |
|
|
or
Code: |
signed int16 Y;
Y = abs(++y);
|
or
Code: |
int16 Y;
Y = (++Y % 32768);
|
|
|
![](templates/subSilver/images/spacer.gif) |
|