prgmode.ino 2.5 KB

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