Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
jobitjoseph authored Feb 3, 2023
1 parent 6ae8541 commit ad02a36
Showing 1 changed file with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
EEPROM_cycle_write
A simple example write eeprom content one by one.
It will continue after power cycle.
created 2020
by Deqing Sun for use with CH55xduino
This example code is in the public domain.
*/

uint8_t writePtr = 0;
uint8_t writeData = 0;

void dumpEEPROM() {
USBSerial_println("DataFalsh Dump:");
for (uint8_t i = 0; i < 128; i++) {
uint8_t eepromData = eeprom_read_byte(i);
if (eepromData < 0x10) USBSerial_print((char)'0');
USBSerial_print(eepromData, HEX);
USBSerial_print((char)',');
if ((i & 15) == 15) USBSerial_println();
}
USBSerial_flush();
}

void setup() {
for (writePtr = 0; writePtr < 128; writePtr++) {
uint8_t eepromData = eeprom_read_byte(writePtr);
if (writePtr != eepromData) break;
}
writeData = writePtr;
if (writePtr >= 128) writePtr = 0;
}

void loop() {
delay(5000);
USBSerial_print("Write ");
USBSerial_print(writeData, HEX);
USBSerial_print(" to addr: ");
USBSerial_println(writePtr, HEX);
eeprom_write_byte(writePtr, writeData);
writeData++;
writePtr++;
if (writePtr >= 128) writePtr = 0;
dumpEEPROM();
}

0 comments on commit ad02a36

Please sign in to comment.