1
0

prgmode.ino 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. entering the programming mode
  3. */
  4. #define BLINK_DELAY 250
  5. #define SHOW_DELAY 500
  6. #define KEY_DELAY 250
  7. enum PROGRAMMING_MODE {ADDRESS, COMMAND, DATA};
  8. PROGRAMMING_MODE prgMode;
  9. void programMode() {
  10. // checking if advance programmer board connected?
  11. #ifdef SPS_ENHANCEMENT
  12. if (digitalRead(SW_SEL) == 0) {
  13. advancePrg();
  14. }
  15. else {
  16. #endif
  17. dbgOutLn("PrgMode");
  18. blinkAll();
  19. while (digitalRead(SW_PRG) == 0) {
  20. // waiting for PRG to release
  21. }
  22. prgMode = ADDRESS;
  23. addr = 0;
  24. do {
  25. blinkD1();
  26. dbgOut("Adr:");
  27. dbgOutLn(addr);
  28. // LoNibble Adresse anzeigen
  29. doPort(addr);
  30. delay(SHOW_DELAY);
  31. blinkD2();
  32. // HiNibble Adresse anzeigen
  33. data = (addr & 0xf0) >> 4; //Adresse anzeigen
  34. doPort(data);
  35. delay(SHOW_DELAY);
  36. byte Eebyte = EEPROM.read(addr);
  37. data = Eebyte & 15;
  38. com = Eebyte >> 4;
  39. blinkD3();
  40. prgMode = COMMAND;
  41. dbgOutLn("com");
  42. doPort(com); //show command
  43. do {
  44. if (digitalRead(SW_SEL) == 0) {
  45. delay(KEY_DELAY);
  46. com += 1;
  47. com = com & 0x0F;
  48. doPort(com);
  49. }
  50. }
  51. while (digitalRead(SW_PRG) == 1);
  52. delay(DEBOUNCE);
  53. blinkD4();
  54. prgMode = DATA;
  55. dbgOutLn("dat");
  56. doPort(data); //show data
  57. do {
  58. if (digitalRead(SW_SEL) == 0) {
  59. delay(KEY_DELAY);
  60. data += 1;
  61. data = data & 0x0F;
  62. doPort(data);
  63. }
  64. }
  65. while (digitalRead(SW_PRG) == 1); // S2 = 1
  66. delay(DEBOUNCE);
  67. byte newValue = (com << 4) + data;
  68. if (newValue != Eebyte) {
  69. EEPROM.write(addr, newValue); // Writeeeprom Eebyte , Addr
  70. blinkAll();
  71. }
  72. addr += 1;
  73. }
  74. while (true);
  75. #ifdef SPS_ENHANCEMENT
  76. }
  77. #endif
  78. }
  79. void blinkAll() {
  80. blinkNull();
  81. doPort(0x0F);
  82. delay(BLINK_DELAY);
  83. }
  84. void blinkD1() {
  85. blinkNull();
  86. doPort(0x01);
  87. delay(BLINK_DELAY);
  88. blinkNull();
  89. }
  90. void blinkD2() {
  91. blinkNull();
  92. doPort(0x02);
  93. delay(BLINK_DELAY);
  94. blinkNull();
  95. }
  96. void blinkD3() {
  97. blinkNull();
  98. doPort(0x04);
  99. delay(BLINK_DELAY);
  100. blinkNull();
  101. }
  102. void blinkD4() {
  103. blinkNull();
  104. doPort(0x08);
  105. delay(BLINK_DELAY);
  106. blinkNull();
  107. }
  108. void blinkNull() {
  109. doPort(0x00);
  110. delay(BLINK_DELAY);
  111. }