-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ae8541
commit ad02a36
Showing
1 changed file
with
49 additions
and
0 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
...x/libraries/Generic_Examples/examples/06.EEPROM/EEPROM_cycle_write/EEPROM_cycle_write.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} |