Name:
peek
Syntax:

PEEK location,variable,variable,WORD wordvariable...

Location - is a variable/constant specifying a register address.

Variable - is a byte variable where the data is returned. To use a word variable the keyword WORD must be used before the wordvariable name.

Description:

Read data from the microcontroller RAM registers.  This allows use of additional storage variables not defined by the bxx variables.

For M2 parts

The 14M2, 18M2+, 20M2 have 512 bytes of user RAM.

The 08M2+ has 128 bytes of user RAM.

The older 18M2 has 256 bytes of user RAM.

The peek and poke commands are used to read and write to all the user RAM. However the lower 28 bytes (addresses 0 to 27) also correspond to the variables b0 to b27. Therefore these lower bytes can be accessed in two ways, via the bxx variable name or via the peek/poke command. The higher variables can only be accessed via the peek/poke commands.

See the peeksfr and pokesfr commands for details on how to access the internal microcontroller SFR (special function registers).

Note that on the older 18M2 part bytes 128-255 are reserved during parallel multi-tasking mode (they are freely available in single task mode). This is a restriction of the limited available RAM on this particular part and does not apply to the 14M2/18M2+/20M2 parts.

For X2 parts

The 20X2 parts have 128 bytes of user RAM (+128 more in scratchpad)

The 28X2 parts have 256 bytes of user RAM (+1024 more in scratchpad)

The 40X2 parts have 256 bytes of user RAM (+1024 more in scratchpad)

The peek and poke commands are used to read and write to all the user RAM. However the lower 56 bytes (addresses 0 to 55) also correspond to the variables b0 to b55. Therefore these lower bytes can be accessed in two ways, via the bxx variable name or via the peek/poke command. The higher variables can only be accessed via the peek/poke commands.

See the peeksfr and pokesfr commands for details on how to access the internal microcontroller SFR (special function registers).

For non M2/X2 parts

The function of the poke/peek commands is two fold. The most commonly used function is to store temporary byte data in the microcontrollers spare 'storage variable' memory. This allows the general purpose variables (b0, b1 etc.) to be re-used in calculations.

Addresses $50 to $7E are general purpose registers that can be used freely
Addresses $C0 to $EF can also be used by PICAXE-18X
Addresses $C0 to $FF can also be used by PICAXE-28X, 40X
Addresses $C0 to $EF can also be used by PICAXE-28X1, 40X1

The second function of the peek command is for experienced users to study the internal microcontroller SFR (special function registers).

Addresses $00 to $1F and $80 to $9F are special function registers (e.g. PORTB) which determine how the microcontroller operates. Avoid using these addresses unless you know what you are doing! The command uses the microcontroller FSR register which can address register banks 0 and 1 only.

Addresses $20 to $4F and $A0 to $BF are general purpose registers reserved for use with the PICAXE bootstrap interpreter. Poking these registers will produce unexpected results and could cause the interpreter to crash.

When word variables are used (with the keyword WORD) the two bytes of the word are saved/retrieved in a little endian manner (ie low byte at address, high byte at address + 1).

 

Applies To:
All (except 08)
See Also:
Related Create:
    Share:
    Print:

    Read data from a microcontroller RAM register

    Read the byte value in location 80, and transfer it to b1, then transfer the data in locations 80 and 81 to w1

    Code Example:
    	peek 80,b1		; put value of register 80 into variable b1
    	peek 80, word w1
    Copy Code Submit an Example

    Submit Your Own Code!

    You must be logged in to submit code examples. Login now.