Name:
poke
Syntax:

POKE location,data,data,WORD wordvariable...

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

Data - is a variable/constant which provides the data byte to be written. To use a word variable the keyword WORD must be used before the wordvariable)

Description:

Write data into FSR location. This allows use of registers not defined by b0, b1 etc.

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 three ways, via the bxx variable name or via the peek/poke command or via the @bptr variable. The higher variables can be accessed via the peek/poke commands or @bptr variable.

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 three ways, via the bxx variable name or via the peek/poke command or via the @bptr variable. The higher variables can be accessed via the peek/poke commands or @bptr variable.

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. Remember that to save a word variable two separate poke/peek commands will be required - one for each of the two bytes that form the word.

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 poke command is for experienced users to write values to 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:

    Write data to a microcontroller RAM register

    Write the value of b1 to location 80, then write the data in w1 to locations 80 and 81

    Code Example:
    	poke 80,b1		; save value of b1 in register 80
    	poke 80, word w1
    Copy Code Submit an Example

    Submit Your Own Code!

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