|
@@ -7,12 +7,10 @@
|
|
#endif
|
|
#endif
|
|
|
|
|
|
void serialPrg() {
|
|
void serialPrg() {
|
|
- //int value1, value2, value3, value4;
|
|
|
|
byte value;
|
|
byte value;
|
|
bool endOfPrg = false;
|
|
bool endOfPrg = false;
|
|
bool endOfFile = false;
|
|
bool endOfFile = false;
|
|
byte data[32];
|
|
byte data[32];
|
|
- char tmp[16];
|
|
|
|
word readAddress;
|
|
word readAddress;
|
|
int crc, readcrc;
|
|
int crc, readcrc;
|
|
byte count;
|
|
byte count;
|
|
@@ -21,7 +19,7 @@ void serialPrg() {
|
|
addr = 0;
|
|
addr = 0;
|
|
Serial.end();
|
|
Serial.end();
|
|
Serial.begin(BAUDRATE);
|
|
Serial.begin(BAUDRATE);
|
|
- Serial.println("serPrgStart");
|
|
|
|
|
|
+ Serial.println();
|
|
Serial.println("waiting for command:");
|
|
Serial.println("waiting for command:");
|
|
Serial.println("w: write HEX file, r: read EPPROM, e: end");
|
|
Serial.println("w: write HEX file, r: read EPPROM, e: end");
|
|
while (!endOfPrg) {
|
|
while (!endOfPrg) {
|
|
@@ -125,14 +123,14 @@ void serialPrg() {
|
|
if (myChar == 'r') {
|
|
if (myChar == 'r') {
|
|
// write eeprom as hexfile to receiver
|
|
// write eeprom as hexfile to receiver
|
|
Serial.println("EEPROM data:");
|
|
Serial.println("EEPROM data:");
|
|
- byte checksum = 0;
|
|
|
|
|
|
+ int checksum = 0;
|
|
for (int addr = 0; addr <= E2END; addr++) {
|
|
for (int addr = 0; addr <= E2END; addr++) {
|
|
value = EEPROM.read(addr);
|
|
value = EEPROM.read(addr);
|
|
- if ((addr % 16) == 0) {
|
|
|
|
|
|
+ if ((addr % 8) == 0) {
|
|
printCheckSum(checksum);
|
|
printCheckSum(checksum);
|
|
checksum = 0;
|
|
checksum = 0;
|
|
- Serial.print(":10");
|
|
|
|
- checksum += 0x10;
|
|
|
|
|
|
+ Serial.print(":08");
|
|
|
|
+ checksum += 0x08;
|
|
printHex16(addr);
|
|
printHex16(addr);
|
|
checksum += (addr >> 8);
|
|
checksum += (addr >> 8);
|
|
checksum += (addr & 0x00FF);
|
|
checksum += (addr & 0x00FF);
|
|
@@ -161,20 +159,29 @@ char getNextChar() {
|
|
}
|
|
}
|
|
return Serial.read();
|
|
return Serial.read();
|
|
}
|
|
}
|
|
-void printCheckSum(byte checksum) {
|
|
|
|
|
|
+
|
|
|
|
+void printCheckSum(int value) {
|
|
|
|
+ int checksum = value & 0xFF;
|
|
|
|
+ checksum = (checksum ^ 0xFF) + 1;
|
|
printHex8(checksum);
|
|
printHex8(checksum);
|
|
Serial.println();
|
|
Serial.println();
|
|
}
|
|
}
|
|
|
|
|
|
void printHex8(int num) {
|
|
void printHex8(int num) {
|
|
- char tmp[16];
|
|
|
|
- sprintf(tmp, "%.2X", num);
|
|
|
|
|
|
+ char tmp[3];
|
|
|
|
+ tmp[0] = nibbleToHex(num >> 4);
|
|
|
|
+ tmp[1] = nibbleToHex(num);
|
|
|
|
+ tmp[2] = 0x00;
|
|
Serial.print(tmp);
|
|
Serial.print(tmp);
|
|
}
|
|
}
|
|
|
|
|
|
void printHex16(int num) {
|
|
void printHex16(int num) {
|
|
- char tmp[16];
|
|
|
|
- sprintf(tmp, "%.4X", num);
|
|
|
|
|
|
+ char tmp[5];
|
|
|
|
+ tmp[0] = nibbleToHex(num >> 12);
|
|
|
|
+ tmp[1] = nibbleToHex(num >> 8);
|
|
|
|
+ tmp[2] = nibbleToHex(num >> 4);
|
|
|
|
+ tmp[3] = nibbleToHex(num);
|
|
|
|
+ tmp[4] = 0x00;
|
|
Serial.print(tmp);
|
|
Serial.print(tmp);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -186,3 +193,13 @@ byte hexToByte (char c) {
|
|
return (c - 'A') + 10;
|
|
return (c - 'A') + 10;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+byte nibbleToHex (byte value) {
|
|
|
|
+ byte c = value & 0x0F;
|
|
|
|
+ if ( (c >= 0) && (c <= 9) ) {
|
|
|
|
+ return c + '0';
|
|
|
|
+ }
|
|
|
|
+ if ( (c >= 10) && (c <= 15) ) {
|
|
|
|
+ return (c + 'A') - 10;
|
|
|
|
+ }
|
|
|
|
+}
|