prgmode.ino 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. entering the programming mode
  3. */
  4. #define BLINK_DELAY 500
  5. #define SHOW_DELAY 1000
  6. #define KEY_DELAY 250
  7. const byte demoPrg[] = { 0x4F, 0x59, 0x1F, 0x29, 0x10, 0x29, 0x5A, 0x40,
  8. 0x59, 0x64, 0x54, 0x29, 0x4F, 0x59, 0x10, 0xCD,
  9. 0x11, 0x28, 0xCC, 0x18, 0x28, 0x4F, 0x59, 0x5A,
  10. 0x72, 0x26, 0xC0, 0x35, 0x80, 0x90, 0xFF
  11. };
  12. enum PROGRAMMING_MODE {ADDRESS, COMMAND, DATA};
  13. PROGRAMMING_MODE prgMode;
  14. void prgDemoPrg() {
  15. byte value = EEPROM.read(0);
  16. if (value == 0xFF) {
  17. value = EEPROM.read(1);
  18. if (value == 0xFF) {
  19. for (byte i = 0; i < sizeof(demoPrg);i++) {
  20. EEPROM.write(i, demoPrg[i]);
  21. }
  22. }
  23. }
  24. }
  25. void programMode() {
  26. // checking if advance programmer board connected?
  27. #ifdef SPS_ENHANCEMENT
  28. if (digitalRead(SW_SEL) == 0) {
  29. advancePrg();
  30. }
  31. else {
  32. #endif
  33. dbgOutLn("PrgMode");
  34. // light up all LEDs
  35. doPort(0x08);
  36. while (digitalRead(SW_PRG) == 0) {
  37. // waiting for PRG to release
  38. }
  39. blinkAll();
  40. prgMode = ADDRESS;
  41. addr = 0;
  42. do {
  43. blinkD1();
  44. dbgOut("Adr:");
  45. dbgOutLn(addr);
  46. // LoNibble Adresse anzeigen
  47. doPort(addr);
  48. delay(SHOW_DELAY);
  49. blinkD2();
  50. // HiNibble Adresse anzeigen
  51. data = (addr & 0xf0) >> 4; //Adresse anzeigen
  52. doPort(data);
  53. delay(SHOW_DELAY);
  54. byte Eebyte = EEPROM.read(addr);
  55. data = Eebyte & 15;
  56. com = Eebyte >> 4;
  57. blinkD3();
  58. prgMode = COMMAND;
  59. dbgOutLn("com");
  60. doPort(com); //show command
  61. do {
  62. if (digitalRead(SW_SEL) == 0) {
  63. delay(KEY_DELAY);
  64. com += 1;
  65. com = com & 0x0F;
  66. doPort(com);
  67. }
  68. }
  69. while (digitalRead(SW_PRG) == 1);
  70. delay(DEBOUNCE);
  71. blinkD4();
  72. prgMode = DATA;
  73. dbgOutLn("dat");
  74. doPort(data); //show data
  75. do {
  76. if (digitalRead(SW_SEL) == 0) {
  77. delay(KEY_DELAY);
  78. data += 1;
  79. data = data & 0x0F;
  80. doPort(data);
  81. }
  82. }
  83. while (digitalRead(SW_PRG) == 1); // S2 = 1
  84. delay(DEBOUNCE);
  85. byte newValue = (com << 4) + data;
  86. if (newValue != Eebyte) {
  87. EEPROM.write(addr, newValue); // Writeeeprom Eebyte , Addr
  88. blinkAll();
  89. }
  90. addr += 1;
  91. }
  92. while (true);
  93. #ifdef SPS_ENHANCEMENT
  94. }
  95. #endif
  96. }
  97. void blinkAll() {
  98. blinkNull();
  99. doPort(0x0F);
  100. delay(BLINK_DELAY);
  101. }
  102. void blinkD1() {
  103. blinkNull();
  104. doPort(0x01);
  105. delay(BLINK_DELAY);
  106. blinkNull();
  107. }
  108. void blinkD2() {
  109. blinkNull();
  110. doPort(0x02);
  111. delay(BLINK_DELAY);
  112. blinkNull();
  113. }
  114. void blinkD3() {
  115. blinkNull();
  116. doPort(0x04);
  117. delay(BLINK_DELAY);
  118. blinkNull();
  119. }
  120. void blinkD4() {
  121. blinkNull();
  122. doPort(0x08);
  123. delay(BLINK_DELAY);
  124. blinkNull();
  125. }
  126. void blinkNull() {
  127. doPort(0x00);
  128. delay(BLINK_DELAY);
  129. }