1
0

serialprg.ino 1.1 KB

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