1
0

prgmode.ino 2.2 KB

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