Pointers in 14M2 / 20M2

nerdegutta

Senior Member
Hi.

Have read Manual2, but I'm either blind or just plain st....

Where is @bptr stored? In the 0-255 places in the EEPROM or in free space in program memory?

- nerdegutta
 

inglewoodpete

Senior Member
Tricky to answer because your question is not 100% clear to me.

Without opening the manual and repeating what it says there, in a 14M2 or 20M2, bptr is a byte-size pointer that always points at a user RAM location.

So the command bptr = 100 sets up the pointer to point at RAM location 100. If bptr = 100, the partial command @bptr refers to the contents of RAM location 100.

So this sequence does this:
Code:
bptr = 100  ;point at RAM location 100
@bptr = 27  ;Load the value 27 into RAM location 100
b1 = @bptr  ;Copy the value (27) stored where bptr is pointing (100) into register b1
Does that help?
 

nerdegutta

Senior Member
Where is the RAM? Within the 0-255 EEPROM table? If it is "outside" of the EEPROM, how do I know where I can start use it? Is it possible to make a table with 28 places in RAM?

- nerdegutta
 

inglewoodpete

Senior Member
The PICAXE has 3 sorts of storage. RAM, EEPROM and Table (flash)
  • RAM is volatile memory, usually 256 512 bytes in most PICAXEs but the X2 models have more, called "scratchpad RAM". bptr, Peek and Poke commands are used to access this data memory. Data stored in volatile memory is lost when the power is removed. Edit: for more details, read the Peek command in Manual 2.
  • EEPROM is non-volatile memory, meaning that the stored values are not lost when power is removed. It can be preprogrammed at download time. Obviously, it can be read with the "Read" command from your program. Your code can also write to this memory using the "Write" command.
  • Table memory is also non-volatile memory but can only be changed with a download from the programming editor. It is stored in flash memory, with the program. Your program can read this data with the "ReadTable" command.
Yes, you can lay out a table of data in RAM. However, the PE does not have special formatting commands or structures like arrays.
 
Last edited:

nerdegutta

Senior Member
The PICAXE has 3 sorts of storage. RAM, EEPROM and Table (flash)
  • RAM is volatile memory, usually 256 bytes in most PICAXEs but the X2 models have more, called "scratchpad RAM". bptr, Peek and Poke commands are used to access this data memory. Data stored in volatile memory is lost when the power is removed.
OK.

So the M2 have 256 bytes RAM, that I can use with bptr, Peed and Poke?

How do I know its starting address?


- nerdgutta
 

darb1972

Senior Member
Have a look at the PICAXE manual 1, from page 52 onwards. Page 54 gives you details on memory locations. I gather that is what you are looking for?
 

inglewoodpete

Senior Member
First, let me correct something I posted earlier. M2 parts have 512 bytes of RAM, so bptr must be 9 bits wide and able to address RAM from 0 to 511. I will update my earlier posts.

Most of the detail is in Command Manual #2, under the Peek command description. RAM locations 0 to 27 in the M2 devices are actually mapped to registers b0 to b27 (w0 to 13), so offer another way to reach the register data. However, I would avoid doing this because it would be too easy the corrupt your data in b0 to b27.

So the first generally available RAM location in M2 PICAXEs is byte 28.
 

nerdegutta

Senior Member
OK, hopefully I got it now....

I can use poke to store bytes in RAM, starting from address 28. Manual 1 page 54, says 28 to 484 is available.

From there I can manipulate the bytes and store it in EEPROM, with the write, location, variable. Later I can read it with read, location, variable.

Thanks for clarifying.

- nerdegutta
 

Technical

Technical Support
Staff member
Yes.
But you can also poke 0-27 is you want, remembering they are the same as b0-b27.

Also

poke 28,value

is the same as

bptr = 28
@bptr = value

So you use '@bptr' to peek/poke the particular address that is the defined by the value in bptr.
 
Top