04 – How to read and write to 74LC16B memory in PICAXE?

Like everything else in PICAXE it is very easy to address I2C memory like the 74LC16B and the question: How to read and write to 74LC16B memory is easily answered. The example uses the PICAXE Development Board (AXE091) but I will provide a circuit diagram for those who want to experiment without their own circuit.


The Write Protect (WP) pin is pulled low to ground with a 10k resistor. This disable the write protect of the memory. To enable write protect the WP pin must be pulled high to +5V but in this mode you will not be able to write to the memory.

Important information to know about the 24LC16B memory chip for implementation and experimentation. The memory on the 24LC16B is divided into eight blocks of 256 x 8-bits and that gives eight blocks of 256 bytes. Giving a total memory of 2k bytes. For the 24LC16B the address of the memory blocks is incorporated in the I2C slave address, %1010bbbx where the bbb is the memory block address and the x bit doesn’t matter. 


The I2C Slave Addresses for the memory blocks are:

Block 0 – Slave Address = %10100000 = 160
Block 1 – Slave Address = %10100010 = 162
Block 2 – Slave Address = %10100100 = 164
Block 3 – Slave Address = %10100110 = 166
Block 4 – Slave Address = %10101000 = 168
Block 5 – Slave Address = %10101010 = 170
Block 6 – Slave Address = %10101100 = 172
Block 7 – Slave Address = %10101110 = 174

With this information we can now address all the memory across memory blocks. Let have a look at the example:

The example is self explanatory and not difficult to follow. a For next loop is used to address the memory blocks in sequence as in the above listing of the memory block addresses in decimal notation. In the first part of the program a counter value is written to every byte in the specific block and displayed on a serial LCD. The process is then repeated for all the memory blocks. In the second part of the program all the bytes in a memory block is read and displayed on the serial LCD. The process repeats itself for all the memory blocks.

You can download the program file, Writing and Reading 24LC16B memory by right clicking on it and selecting ‘save link as’ from the popup menu.