Memory Commands Intro Edit

Memory commands may be used to access memory directly. RAM, EEPROM and even program memory may be accessed, depending on the command.

Note: The use of program memory for data storage is described on page 45 under Tables.

More details concerning various types of memory are found on page 35.

Memory commands are provided for advanced programmers, and memory usage and addressing is not discussed in detail in this manual. Users should note that all PIC16F876/7 registers are available via pre-defined variables, contents of variables are available via their names, etc. so in the majority of cases the commands described in this section are not essential. We have provided these commands for backwards compatibility, and for the convenience of advanced programmers with unusual applications.

Note: For details of register and memory addressing and use please consult the H8/3664F or H8/3687F hardware manual, available at

This chapter contains the following sections:

  • Memory Commands
    • Peek
    • Poke
    • Read
    • Write
    • ReadDM
    • WriteDM

Conventions Used in this Chapter Edit

{ ... } represent optional components in a command. The { } are not to be included.
[ ... ] used for lists - the [ ] are required.
( ... ) used for some arguments. The ( ) are required.


These commands are used to read and write to RAM locations.


peek address, variable
poke address, expression
address is a variable or constant that specifies the RAM location (see the Warning under Notes, below).
variable is a byte variable used to store the contents of the RAM location for the PEEK command.

expression is a variable, constant or expression that provides an 8 bit value to be stored in RAM with the POKE command.


PEEK and Poke start at the begining of RAM so the first ram location is 0 indexed. The actual ram location in the Hitachi memory map is 0xF780 to 0xFF7F

Registers start at 0xFF80, but because PEEK and POKE automatically offset 0 to 0xF780 the registers appear to start at 0x800

In most cases it is easier to use variable names (or register names, all of which are available in Atom BASIC) to access memory.

Important: Since RAM is used to store the Atom Pro's internal registers as well as user data, careless use of the POKE command could adversely affect the operation of the controller chip. Make sure you fully understand the memory map of the H8/3664 before using POKE.


regvalue var byte
peek $1F,regvalue $1F is the address of register adcon0

will give the same result as

regvalue var byte
regvalue = adcon0 ; adcon0 is a pre-defined variable


These commands are used to read and write one byte at a time to EEPROM locations of Atom Pro Plus modules (see Notes below). In this respect they are equivalent to PEEK and POKE which read and write to RAM locations.

Note: Although PEEK and POKE are usually redundant because there exist more convenient ways to access RAM, these other ways don't exist for EEPROM, therefore READ and WRITE are quite useful.


read address variable
write address expression
address is a variable or constant that specifies the EEPROM address (0 - 255) to read from or write to.
variable is a byte variable which will store the value read from EEPROM.
expression is a variable, constant or expression that generates the 8 bit value to store at address.


The Atom Pro 24 and 28 pin modules do not have EEPROM so these commands don't apply. The Atom Pro 40 pin (Atom Pro Plus) module has 4K EEPROM.

An external I2C EEPROM may be connected to p10 (SCL)/p11 (SDA) of the Atom Pro modules to use the READ and WRITE commands.

READ and WRITE execute when your program is running, not when it is first written to program memory. This lets you change EEPROM values "on the fly". Users should note the following:

  • EEPROM can be read an indefinite number of times at the same rate as RAM can be read.
  • EEPROM can be written to only a limited number of times (around 10 million), so it's generally better to use RAM for values that change frequently.
  • EEPROM is much slower to write than is RAM, so unnecessary use of WRITE can slow down program execution.

For example, if you change an EEPROM value once per second (about 86400 times per day) your Atom Pro's EEPROM could be worn out in about 116 days. This is to be avoided.


contents var byte
read 100,contents

will read EEPROM address 100 and store the 8 bit result in contents.


Read or write a sequence of values from/to EEPROM locations of supported Atom Pro modules. Except that many values may be read or written by one command, these commands are essentially identical to READ and WRITE, above.


readdm address,[{modifier} var, ... {modifier} var]
writedm address,[{modifier} expr, ... {modifier} expr]
address is a variable or constant that specifies the first EEPROM address to read from or write to. Subsequent reads or writes within the same command will be sequential.
modifier is any valid command modifier (see page 69). See the HSERIN and HSEROUT commands for examples of the use of these modifiers.
var is a variable, or sequence of byte variables, in which the results of the EEPROM reads will be stored.
expr is a byte variable, constant or expression (or a sequence of such) that generates data to be stored in EEPROM. Values are stored sequentially beginning at address.


See the READ, WRITE commands in the previous section for supported models and other information.


temp var byte(5)
readdm 100,[temp(0),temp(1),temp(3)]

will read the values at addresses 100, 101 and 102 and store them in temp(0), temp(1) and temp(2) respectively.

temp var byte(5)
code to set values of temp(n)
writedm 100,[dec1 temp(0), dec1 temp(1)]

will write the values of temp(0) and temp(1), converted to decimal ASCII characters, in EEPROM addresses 100 and 101, respectively. Only one decimal digit (the least significant) is written in each case.