1
0

serialprg.ino 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. void serialPrg() {
  2. int value1, value2, value3, value4;
  3. byte value;
  4. bool endOfPrg = false;
  5. addr = 0;
  6. Serial.end();
  7. Serial.begin(57600);
  8. Serial.println("serPrgStart");
  9. while (!endOfPrg) {
  10. while (Serial.available() > 0) {
  11. // look for the next valid integer in the incoming serial stream:
  12. char myChar = Serial.read();
  13. if (myChar == 'd') {
  14. for (byte i = 0; i < 8; i++) {
  15. char c;
  16. while (!Serial.available()) {
  17. }
  18. do {
  19. c = Serial.read();
  20. } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
  21. value = hexToByte(c);
  22. while (!Serial.available()) {
  23. }
  24. do {
  25. c = Serial.read();
  26. } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
  27. value = value * 16 + hexToByte(c);
  28. EEPROM.write(addr + i, value);
  29. }
  30. Serial.print("w:");
  31. for (byte i = 0; i < 8; i++) {
  32. value = EEPROM.read(addr + i);;
  33. Serial.print(value, HEX);
  34. if (i < 7) {
  35. Serial.print(",");
  36. }
  37. }
  38. Serial.println();
  39. addr = addr + 8;
  40. }
  41. if (myChar == '*') {
  42. endOfPrg = true;
  43. }
  44. }
  45. }
  46. Serial.println("end");
  47. Serial.end();
  48. doReset();
  49. }
  50. byte hexToByte (char c) {
  51. if ( (c >= '0') && (c <= '9') ) {
  52. return c - '0';
  53. }
  54. if ( (c >= 'A') && (c <= 'F') ) {
  55. return (c - 'A') + 10;
  56. }
  57. }