|
@@ -1,9 +1,22 @@
|
|
/*
|
|
/*
|
|
SPS System mit dem Arduino.
|
|
SPS System mit dem Arduino.
|
|
|
|
+ Version 0.12
|
|
|
|
+ 27.01.2019
|
|
|
|
+ - adding demo program,
|
|
|
|
+ 11.01.2018
|
|
|
|
+ - some refactoring
|
|
|
|
+
|
|
|
|
+ 07.01.2018
|
|
|
|
+ - programming: 1/2 duty cycle for 0 values in address display
|
|
|
|
+
|
|
|
|
+ Version 0.11
|
|
|
|
+ 17.12.2018
|
|
|
|
+ - adding Shift left and shift right to register A
|
|
|
|
+
|
|
Version 0.10
|
|
Version 0.10
|
|
7.12.2018
|
|
7.12.2018
|
|
- new define for serial programming
|
|
- new define for serial programming
|
|
-
|
|
|
|
|
|
+
|
|
18.11.2018 WKLA
|
|
18.11.2018 WKLA
|
|
- new standard programming mode
|
|
- new standard programming mode
|
|
I added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
|
|
I added a new programming mode for the default programming, because i thing the old one was a little bit clumsy.
|
|
@@ -11,23 +24,23 @@
|
|
Starting with PRG pushed after Reset.
|
|
Starting with PRG pushed after Reset.
|
|
as a result, all LEDs will shortly blink
|
|
as a result, all LEDs will shortly blink
|
|
now you are in programming mode.
|
|
now you are in programming mode.
|
|
- * the D1 LED will blink
|
|
|
|
- * the higher nibble of the address will be shown
|
|
|
|
- * the D2 LED will blink
|
|
|
|
- * the lower nibble of the address will be shown
|
|
|
|
- * the D3 LED will blink
|
|
|
|
- * the command part (high nibble) will be shown
|
|
|
|
- * with SEL you can step thru all commands
|
|
|
|
- * PRG will save the command
|
|
|
|
- * the D4 LED will blink
|
|
|
|
- * the data part (low nibble) will be shown
|
|
|
|
- * with SEL you can step thru all datas
|
|
|
|
- * PRG will save the data
|
|
|
|
- * if the new value has been changed, all LEDs will flash as the byte will be written to the EEPROM
|
|
|
|
- * address will be increased and now it will start with blinking of the D1 LED
|
|
|
|
- *
|
|
|
|
- * To leave the programming simply push reset.
|
|
|
|
-
|
|
|
|
|
|
+ the D1 LED will blink
|
|
|
|
+ the higher nibble of the address will be shown
|
|
|
|
+ the D2 LED will blink
|
|
|
|
+ the lower nibble of the address will be shown
|
|
|
|
+ the D3 LED will blink
|
|
|
|
+ the command part (high nibble) will be shown
|
|
|
|
+ with SEL you can step thru all commands
|
|
|
|
+ PRG will save the command
|
|
|
|
+ the D4 LED will blink
|
|
|
|
+ the data part (low nibble) will be shown
|
|
|
|
+ with SEL you can step thru all datas
|
|
|
|
+ PRG will save the data
|
|
|
|
+ if the new value has been changed, all LEDs will flash as the byte will be written to the EEPROM
|
|
|
|
+ address will be increased and now it will start with blinking of the D1 LED
|
|
|
|
+
|
|
|
|
+ To leave the programming simply push reset.
|
|
|
|
+
|
|
Version 0.9
|
|
Version 0.9
|
|
18.11.2018 WKLA
|
|
18.11.2018 WKLA
|
|
- BUGs entfernt. Release.
|
|
- BUGs entfernt. Release.
|
|
@@ -57,7 +70,7 @@
|
|
*/
|
|
*/
|
|
|
|
|
|
/*
|
|
/*
|
|
- * HEre are the defines used in this software to control special parts of the implementation
|
|
|
|
|
|
+ * Here are the defines used in this software to control special parts of the implementation
|
|
* #define SPS_USE_DISPLAY: using a external TM1637 Display for displaying address and data at one time
|
|
* #define SPS_USE_DISPLAY: using a external TM1637 Display for displaying address and data at one time
|
|
* #define SPS_RECEIVER: using a RC receiver input
|
|
* #define SPS_RECEIVER: using a RC receiver input
|
|
* #define SPS_ENHANCEMENT: all of the other enhancments
|
|
* #define SPS_ENHANCEMENT: all of the other enhancments
|
|
@@ -66,7 +79,9 @@
|
|
* #define SPS_SERIAL_PRG: activates the serial programming feature
|
|
* #define SPS_SERIAL_PRG: activates the serial programming feature
|
|
*/
|
|
*/
|
|
// Program im Debugmodus kompilieren, dann werden zus. Ausgaben auf die serielle Schnittstelle geschrieben.
|
|
// Program im Debugmodus kompilieren, dann werden zus. Ausgaben auf die serielle Schnittstelle geschrieben.
|
|
|
|
+//#define debug
|
|
|
|
|
|
|
|
+// defining different hardware platforms
|
|
#ifdef __AVR_ATtiny861__
|
|
#ifdef __AVR_ATtiny861__
|
|
#define SPS_RCRECEIVER
|
|
#define SPS_RCRECEIVER
|
|
#define SPS_ENHANCEMENT
|
|
#define SPS_ENHANCEMENT
|
|
@@ -80,7 +95,6 @@
|
|
#endif
|
|
#endif
|
|
|
|
|
|
#ifdef __AVR_ATmega328P__
|
|
#ifdef __AVR_ATmega328P__
|
|
-//#define debug
|
|
|
|
#define SPS_USE_DISPLAY
|
|
#define SPS_USE_DISPLAY
|
|
#define SPS_RECEIVER
|
|
#define SPS_RECEIVER
|
|
#define SPS_ENHANCEMENT
|
|
#define SPS_ENHANCEMENT
|
|
@@ -96,6 +110,7 @@
|
|
//#define SPS_TONE
|
|
//#define SPS_TONE
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+// libraries
|
|
#include <debug.h>
|
|
#include <debug.h>
|
|
#include <makros.h>
|
|
#include <makros.h>
|
|
#include <EEPROM.h>
|
|
#include <EEPROM.h>
|
|
@@ -113,138 +128,9 @@
|
|
#include "notes.h"
|
|
#include "notes.h"
|
|
#endif
|
|
#endif
|
|
|
|
|
|
-// Hardwareanbindung
|
|
|
|
-#ifdef __AVR_ATmega328P__
|
|
|
|
-// Arduino Hardware
|
|
|
|
-const byte Din_0 = 0;
|
|
|
|
-const byte Din_1 = 1;
|
|
|
|
-const byte Din_2 = 2;
|
|
|
|
-const byte Din_3 = 3;
|
|
|
|
-
|
|
|
|
-const byte Dout_0 = 4;
|
|
|
|
-const byte Dout_1 = 5;
|
|
|
|
-const byte Dout_2 = 6;
|
|
|
|
-const byte Dout_3 = 7;
|
|
|
|
-
|
|
|
|
-const byte ADC_0 = 0; //(15)
|
|
|
|
-const byte ADC_1 = 1; //(16)
|
|
|
|
-const byte PWM_1 = 9;
|
|
|
|
-const byte PWM_2 = 10;
|
|
|
|
-
|
|
|
|
-#ifdef SPS_RCRECEIVER
|
|
|
|
-const byte RC_0 = 18;
|
|
|
|
-const byte RC_1 = 19;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef SPS_SERVO
|
|
|
|
-const byte SERVO_1 = 9;
|
|
|
|
-const byte SERVO_2 = 10;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-const byte SW_PRG = 8;
|
|
|
|
-const byte SW_SEL = 11;
|
|
|
|
-
|
|
|
|
-#ifdef SPS_USE_DISPLAY
|
|
|
|
-const byte DIGIT_DATA_IO = 12;
|
|
|
|
-const byte DIGIT_CLOCK = 13;
|
|
|
|
-#endif
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef __AVR_ATtiny84__
|
|
|
|
-// ATTiny84 Hardware
|
|
|
|
-const byte Dout_0 = 6;
|
|
|
|
-const byte Dout_1 = 5;
|
|
|
|
-const byte Dout_2 = 4;
|
|
|
|
-const byte Dout_3 = 1;
|
|
|
|
-
|
|
|
|
-const byte Din_0 = 10;
|
|
|
|
-const byte Din_1 = 9;
|
|
|
|
-const byte Din_2 = 8;
|
|
|
|
-const byte Din_3 = 7;
|
|
|
|
-const byte ADC_0 = 0;
|
|
|
|
-const byte ADC_1 = 1;
|
|
|
|
-const byte PWM_1 = 2;
|
|
|
|
-const byte PWM_2 = 3;
|
|
|
|
-#ifdef SPS_RCRECEIVER
|
|
|
|
-const byte RC_0 = 10;
|
|
|
|
-const byte RC_1 = 9;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef SPS_SERVO
|
|
|
|
-const byte SERVO_1 = 2;
|
|
|
|
-const byte SERVO_2 = 3;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-const byte SW_PRG = 0;
|
|
|
|
-const byte SW_SEL = 8;
|
|
|
|
|
|
+#include "hardware.h"
|
|
|
|
|
|
-#ifdef SPS_USE_DISPLAY
|
|
|
|
-const byte DIGIT_DATA_IO = 4;
|
|
|
|
-const byte DIGIT_CLOCK = 5;
|
|
|
|
-#endif
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef __AVR_ATtiny4313__
|
|
|
|
-// ATTiny4313 Hardware
|
|
|
|
-const byte Dout_0 = 0;
|
|
|
|
-const byte Dout_1 = 1;
|
|
|
|
-const byte Dout_2 = 2;
|
|
|
|
-const byte Dout_3 = 3;
|
|
|
|
-
|
|
|
|
-const byte Din_0 = 4;
|
|
|
|
-const byte Din_1 = 5;
|
|
|
|
-const byte Din_2 = 6;
|
|
|
|
-const byte Din_3 = 7;
|
|
|
|
-const byte ADC_0 = 13;
|
|
|
|
-const byte ADC_1 = 14;
|
|
|
|
-const byte PWM_1 = 11;
|
|
|
|
-const byte PWM_2 = 12;
|
|
|
|
-
|
|
|
|
-#ifdef SPS_RCRECEIVER
|
|
|
|
-const byte RC_0 = 15;
|
|
|
|
-const byte RC_1 = 16;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef SPS_SERVO
|
|
|
|
-const byte SERVO_1 = 11;
|
|
|
|
-const byte SERVO_2 = 12;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-const byte SW_PRG = 9;
|
|
|
|
-const byte SW_SEL = 8;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef __AVR_ATtiny861__
|
|
|
|
-// ATTiny4313 Hardware
|
|
|
|
-const byte Dout_0 = 0;
|
|
|
|
-const byte Dout_1 = 1;
|
|
|
|
-const byte Dout_2 = 2;
|
|
|
|
-const byte Dout_3 = 3;
|
|
|
|
-
|
|
|
|
-const byte Din_0 = 4;
|
|
|
|
-const byte Din_1 = 5;
|
|
|
|
-const byte Din_2 = 6;
|
|
|
|
-const byte Din_3 = 7;
|
|
|
|
-const byte ADC_0 = 13;
|
|
|
|
-const byte ADC_1 = 14;
|
|
|
|
-const byte PWM_1 = 11;
|
|
|
|
-const byte PWM_2 = 12;
|
|
|
|
-
|
|
|
|
-#ifdef SPS_RCRECEIVER
|
|
|
|
-const byte RC_0 = 15;
|
|
|
|
-const byte RC_1 = 16;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-#ifdef SPS_SERVO
|
|
|
|
-const byte SERVO_1 = 11;
|
|
|
|
-const byte SERVO_2 = 12;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-const byte SW_PRG = 9;
|
|
|
|
-const byte SW_SEL = 8;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
-// Befehle
|
|
|
|
|
|
+// Commands
|
|
const byte PORT = 0x10;
|
|
const byte PORT = 0x10;
|
|
const byte DELAY = 0x20;
|
|
const byte DELAY = 0x20;
|
|
const byte JUMP_BACK = 0x30;
|
|
const byte JUMP_BACK = 0x30;
|
|
@@ -268,8 +154,15 @@ const byte DEBOUNCE = 100;
|
|
const byte subCnt = 7;
|
|
const byte subCnt = 7;
|
|
word subs[subCnt];
|
|
word subs[subCnt];
|
|
|
|
|
|
|
|
+// the actual address of the program
|
|
word addr;
|
|
word addr;
|
|
|
|
+// page register
|
|
word page;
|
|
word page;
|
|
|
|
+// defining register
|
|
|
|
+byte a, b, c, d;
|
|
|
|
+#ifdef SPS_ENHANCEMENT
|
|
|
|
+byte e, f;
|
|
|
|
+#endif
|
|
|
|
|
|
#ifdef SPS_ENHANCEMENT
|
|
#ifdef SPS_ENHANCEMENT
|
|
const byte SAVE_CNT = 16;
|
|
const byte SAVE_CNT = 16;
|
|
@@ -287,12 +180,6 @@ byte stackCnt;
|
|
|
|
|
|
unsigned long tmpValue;
|
|
unsigned long tmpValue;
|
|
|
|
|
|
-byte a, b, c, d;
|
|
|
|
-
|
|
|
|
-#ifdef SPS_ENHANCEMENT
|
|
|
|
-byte e, f;
|
|
|
|
-#endif
|
|
|
|
-
|
|
|
|
#ifdef SPS_SERVO
|
|
#ifdef SPS_SERVO
|
|
Servo servo1;
|
|
Servo servo1;
|
|
Servo servo2;
|
|
Servo servo2;
|
|
@@ -319,6 +206,9 @@ void setup() {
|
|
pinMode(SW_PRG, INPUT_PULLUP);
|
|
pinMode(SW_PRG, INPUT_PULLUP);
|
|
pinMode(SW_SEL, INPUT_PULLUP);
|
|
pinMode(SW_SEL, INPUT_PULLUP);
|
|
|
|
|
|
|
|
+ digitalWrite(Dout_0, 1);
|
|
|
|
+ delay(1000);
|
|
|
|
+ digitalWrite(Dout_0, 0);
|
|
#ifdef SPS_USE_DISPLAY
|
|
#ifdef SPS_USE_DISPLAY
|
|
initDisplay();
|
|
initDisplay();
|
|
#endif
|
|
#endif
|
|
@@ -328,6 +218,7 @@ void setup() {
|
|
initDebug();
|
|
initDebug();
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
+ prgDemoPrg();
|
|
doReset();
|
|
doReset();
|
|
|
|
|
|
if (digitalRead(SW_PRG) == 0) {
|
|
if (digitalRead(SW_PRG) == 0) {
|
|
@@ -336,6 +227,7 @@ void setup() {
|
|
#ifdef SPS_ENHANCEMENT
|
|
#ifdef SPS_ENHANCEMENT
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
pinMode(LED_BUILTIN, OUTPUT);
|
|
#endif
|
|
#endif
|
|
|
|
+
|
|
#ifdef SPS_SERIAL_PRG
|
|
#ifdef SPS_SERIAL_PRG
|
|
if (digitalRead(SW_SEL) == 0) {
|
|
if (digitalRead(SW_SEL) == 0) {
|
|
serialPrg();
|
|
serialPrg();
|
|
@@ -441,26 +333,7 @@ void loop() {
|
|
byte cmd = (value & 0xF0);
|
|
byte cmd = (value & 0xF0);
|
|
byte data = (value & 0x0F);
|
|
byte data = (value & 0x0F);
|
|
|
|
|
|
- dbgOut2(addr, HEX);
|
|
|
|
- dbgOut(":");
|
|
|
|
- dbgOut2(value, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(cmd, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(data, HEX);
|
|
|
|
- dbgOut(",a:");
|
|
|
|
- dbgOut2(a, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(b, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(c, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(d, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(e, HEX);
|
|
|
|
- dbgOut(",");
|
|
|
|
- dbgOut2(f, HEX);
|
|
|
|
- dbgOutLn();
|
|
|
|
|
|
+ debugOutputRegister();
|
|
|
|
|
|
addr = addr + 1;
|
|
addr = addr + 1;
|
|
switch (cmd) {
|
|
switch (cmd) {
|
|
@@ -517,6 +390,14 @@ void loop() {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void debugOutputRegister() {
|
|
|
|
+ dbgOut2(addr, HEX); dbgOut(":"); dbgOut2(value, HEX); dbgOut(",");
|
|
|
|
+ dbgOut2(cmd, HEX); dbgOut(","); dbgOut2(data, HEX); dbgOut(",a:");
|
|
|
|
+ dbgOut2(a, HEX); dbgOut(","); dbgOut2(b, HEX); dbgOut(",");
|
|
|
|
+ dbgOut2(c, HEX); dbgOut(","); dbgOut2(d, HEX); dbgOut(",");
|
|
|
|
+ dbgOut2(e, HEX); dbgOut(","); dbgOut2(f, HEX); dbgOutLn();
|
|
|
|
+}
|
|
|
|
+
|
|
/*
|
|
/*
|
|
output to port
|
|
output to port
|
|
*/
|
|
*/
|
|
@@ -833,6 +714,12 @@ void doCalc(byte data) {
|
|
case 13:
|
|
case 13:
|
|
a = b - a;
|
|
a = b - a;
|
|
break;
|
|
break;
|
|
|
|
+ case 14:
|
|
|
|
+ a = a >> 1;
|
|
|
|
+ break;
|
|
|
|
+ case 15:
|
|
|
|
+ a = a << 1;
|
|
|
|
+ break;
|
|
#endif
|
|
#endif
|
|
default:
|
|
default:
|
|
break;
|
|
break;
|
|
@@ -884,7 +771,7 @@ void doDCount(byte data) {
|
|
}
|
|
}
|
|
|
|
|
|
/*
|
|
/*
|
|
- simple comdition = true skip next command
|
|
|
|
|
|
+ simple condition = true, skip next command
|
|
*/
|
|
*/
|
|
void doSkipIf(byte data) {
|
|
void doSkipIf(byte data) {
|
|
bool skip = false;
|
|
bool skip = false;
|
|
@@ -1047,7 +934,7 @@ void doByte(byte data) {
|
|
case 6:
|
|
case 6:
|
|
if (servo1.attached()) {
|
|
if (servo1.attached()) {
|
|
dbgOut("Srv1:");
|
|
dbgOut("Srv1:");
|
|
- tmpValue = map(a,0, 255,0,180);
|
|
|
|
|
|
+ tmpValue = map(a, 0, 255, 0, 180);
|
|
dbgOutLn(tmpValue);
|
|
dbgOutLn(tmpValue);
|
|
servo1.write(tmpValue);
|
|
servo1.write(tmpValue);
|
|
}
|
|
}
|
|
@@ -1055,7 +942,7 @@ void doByte(byte data) {
|
|
case 7:
|
|
case 7:
|
|
if (servo2.attached()) {
|
|
if (servo2.attached()) {
|
|
dbgOut("Srv2:");
|
|
dbgOut("Srv2:");
|
|
- tmpValue = map(a,0, 255,0,180);
|
|
|
|
|
|
+ tmpValue = map(a, 0, 255, 0, 180);
|
|
dbgOutLn(tmpValue);
|
|
dbgOutLn(tmpValue);
|
|
servo2.write(tmpValue);
|
|
servo2.write(tmpValue);
|
|
}
|
|
}
|