After carefully reading the task and GIF, we have to print all values from EEPROM to the serial terminal.
Also, we have to print 16 values per row, with the address and value in hex format.
So first, we need to know the size of EEPROM in Arduino UNO, we can get it by using the EEPROM.h
library with EEPROM.length()
function.
Once we get the length, i.e. 1024 Bytes for Arduino UNO, we need to print all location data. Also as per the task, we have to ensure
#include <EEPROM.h>
// Define the size of EEPROM (varies depending on microcontroller)
const int EEPROM_SIZE = 512; // For Arduino Uno, update based on your board's EEPROM size.
const int BYTES_PER_ROW = 16; // Bytes to display per row
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println("EEPROM Memory Map:");
Serial.println("Address | Data (in Hex)");
Serial.println("-------------------------");
printEEPROMMap();
}
void loop() {
// No operations in the loop.
}
void printEEPROMMap() {
for (int i = 0; i < EEPROM_SIZE; i += BYTES_PER_ROW) {
// Print starting address of the row
Serial.print("0x");
if (i < 16) Serial.print("0"); // Formatting for single-digit addresses
Serial.print(i, HEX);
Serial.print(" | ");
// Print the data in hexadecimal format
for (int j = 0; j < BYTES_PER_ROW; j++) {
if (i + j < EEPROM_SIZE) {
byte data = EEPROM.read(i + j);
if (data < 16) Serial.print("0"); // Ensure two digits
Serial.print(data, HEX);
Serial.print(" ");
} else {
// If out of bounds, print placeholder
Serial.print("-- ");
}
}
Serial.println();
}
}
As we can see in the code, we have added EEPROM.h
to use EEPROM-based functions.
EEPROM Mapping Logic: void printEEPROMMap()
The below output is of the EEPROM (after writing random values)
The below output is of the Formatted EEPROM. (Writing 0xFF to all EEPROM locations)