prgmode.ino 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. /*
  2. entering the programming mode
  3. */
  4. void programMode() {
  5. // checking if advance programmer board connected?
  6. #ifdef SPS_ENHANCEMENT
  7. if (digitalRead(SW_SEL) == 0) {
  8. advancePrg();
  9. }
  10. else {
  11. #endif
  12. dbgOutLn("PrgMode");
  13. addr = 0;
  14. do {
  15. dbgOut("Adr:");
  16. dbgOutLn(addr);
  17. // LoNibble Adresse anzeigen
  18. doPort(addr);
  19. delay(300);
  20. lighting();
  21. // HiNibble Adresse anzeigen
  22. data = (addr & 0xf0) >> 4; //Adresse anzeigen
  23. doPort(data);
  24. delay(300);
  25. lighting();
  26. byte Eebyte = EEPROM.read(addr);
  27. data = Eebyte & 15;
  28. com = Eebyte >> 4;
  29. dbgOutLn('commando eingeben');
  30. doPort(com); //Befehl anzeigen
  31. digitalWrite(PWM_1, HIGH);
  32. do {
  33. }
  34. while (digitalRead(SW_SEL) == 1); // S2 = 1
  35. delay(DEBOUNCE);
  36. prog = 1; //Phase 1: Befehl anzeigen
  37. do {
  38. dbgOut("C:");
  39. dbgOut(com);
  40. dbgOut(", D:");
  41. dbgOut(data);
  42. dbgOut(", P:");
  43. dbgOutLn(prog);
  44. if (digitalRead(SW_PRG) == 0) {
  45. if (prog == 1) {
  46. prog = 2;
  47. com = 15;
  48. }
  49. if (prog == 2) { //Phase 2: Befehl verändert
  50. com = com + 1;
  51. com = com & 15;
  52. doPort(com);
  53. digitalWrite(PWM_1, HIGH);
  54. }
  55. if (prog == 3) { //Phase 3: Befehl unverändert, Daten ändern
  56. prog = 5;
  57. data = 15;
  58. }
  59. if (prog == 4) { //Phase 4: Befehl und Daten geändert
  60. prog = 5;
  61. data = 15;
  62. }
  63. if (prog == 5) { //Phase 5: Daten verändert
  64. data += 1;
  65. data = data & 15;
  66. doPort(data);
  67. digitalWrite(PWM_1, LOW);
  68. }
  69. delay(DEBOUNCE);
  70. do {
  71. }
  72. while (digitalRead(SW_PRG) == 1);
  73. delay(DEBOUNCE);
  74. }
  75. if (digitalRead(SW_SEL) == 0) {
  76. if (prog == 3) {
  77. prog = 7; //nur angezeigt, nicht verändert
  78. }
  79. if (prog == 4) {
  80. doPort(255 - data);
  81. digitalWrite(PWM_1, LOW);
  82. prog = 6;
  83. }
  84. if (prog == 2) {
  85. doPort(data); // Portd = Dat Or &HF0
  86. digitalWrite(PWM_1, LOW);
  87. prog = 4;
  88. }
  89. if (prog == 6) { //nur Kommando wurde verändert
  90. data = data & 15;
  91. Eebyte = com * 16;
  92. Eebyte = Eebyte + data;
  93. EEPROM.write(addr, Eebyte); // Writeeeprom Eebyte , Addr
  94. doPort(0x0F);
  95. delay(600);
  96. addr += 1;
  97. prog = 0;
  98. }
  99. if (prog == 5) { //Daten wurden verändert
  100. data = data & 15;
  101. Eebyte = com * 16;
  102. Eebyte = Eebyte + data;
  103. EEPROM.write(addr, Eebyte); // Writeeeprom Eebyte , Addr
  104. doPort(0xF0);
  105. delay(600);
  106. addr += 1;
  107. prog = 0;
  108. }
  109. if (prog == 7) {
  110. addr += 1;
  111. prog = 0;
  112. }
  113. delay(DEBOUNCE);
  114. do {
  115. }
  116. while (digitalRead(SW_SEL) == 0);
  117. delay(DEBOUNCE);
  118. }
  119. }
  120. while (prog != 0);
  121. }
  122. while (true);
  123. #ifdef SPS_ENHANCEMENT
  124. }
  125. #endif
  126. }
  127. void lighting() {
  128. doPort(0x0F);
  129. delay(200);
  130. }