Parcourir la source

adding serial interface and programming to Attiny84

Klaas, Wilfried il y a 6 ans
Parent
commit
cb9fcf133e
2 fichiers modifiés avec 72 ajouts et 66 suppressions
  1. 3 3
      SPS/SPS.ino
  2. 69 63
      SPS/serialprg.ino

+ 3 - 3
SPS/SPS.ino

@@ -69,7 +69,7 @@
 #define SPS_TONE
 #endif
 
-#ifdef __AVR_ATinyx4__
+#ifdef __AVR_ATtiny84__
 #define SPS_ENHANCEMENT
 #define SPS_SERVO
 #endif
@@ -127,7 +127,7 @@ const byte DIGIT_CLOCK = 13;
 #endif
 #endif
 
-#ifdef __AVR_ATtinyX4__
+#ifdef __AVR_ATtiny84__
 // ATTiny84 Hardware
 const byte Dout_0 = 6;
 const byte Dout_1 = 5;
@@ -271,7 +271,7 @@ void setup() {
 #endif
 
   // Serielle Schnittstelle einstellen
-#ifndef __AVR_ATtinyX4__
+#ifndef __AVR_ATtiny84__
   initDebug();
 #endif
 

+ 69 - 63
SPS/serialprg.ino

@@ -1,64 +1,70 @@
-
-
-void serialPrg() {
-  int value1, value2, value3, value4;
-  byte value;
-  bool endOfPrg = false;
-
-  addr = 0;
-  Serial.end();
-  Serial.begin(57600);
-  Serial.println("serPrgStart");
-  while (!endOfPrg) {
-    while (Serial.available() > 0) {
-
-      // look for the next valid integer in the incoming serial stream:
-      char myChar = Serial.read();
-      if (myChar == 'd') {
-        for (byte i = 0; i < 8; i++) {
-          char c;
-          while (!Serial.available()) {
-          }
-          do {
-            c = Serial.read();
-          } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
-          value = hexToByte(c);
-
-          while (!Serial.available()) {
-          }
-          do {
-            c = Serial.read();
-          } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
-
-          value = value * 16 + hexToByte(c);
-          EEPROM.write(addr + i, value);
-        }
-        Serial.print("w:");
-        for (byte i = 0; i < 8; i++) {
-          value = EEPROM.read(addr + i);;
-          Serial.print(value, HEX);
-          if (i < 7) {
-            Serial.print(",");
-          }
-        }
-        Serial.println();
-        addr = addr + 8;
-      }
-      if (myChar == '*') {
-        endOfPrg = true;
-      }
-    }
-  }
-  Serial.println("end");
-  Serial.end();
-  doReset();
-}
-
-byte hexToByte (char c) {
-  if ( (c >= '0') && (c <= '9') ) {
-    return c - '0';
-  }
-  if ( (c >= 'A') && (c <= 'F') ) {
-    return (c - 'A') + 10;
-  }
+#ifdef __AVR_ATtiny84__
+#define BAUDRATE 9600
+#endif
+
+#ifdef __AVR_ATmega328P__
+#define BAUDRATE 57600
+#endif
+
+void serialPrg() {
+  int value1, value2, value3, value4;
+  byte value;
+  bool endOfPrg = false;
+
+  addr = 0;
+  Serial.end();
+  Serial.begin(BAUDRATE);
+  Serial.println("serPrgStart");
+  while (!endOfPrg) {
+    while (Serial.available() > 0) {
+
+      // look for the next valid integer in the incoming serial stream:
+      char myChar = Serial.read();
+      if (myChar == 'd') {
+        for (byte i = 0; i < 8; i++) {
+          char c;
+          while (!Serial.available()) {
+          }
+          do {
+            c = Serial.read();
+          } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
+          value = hexToByte(c);
+
+          while (!Serial.available()) {
+          }
+          do {
+            c = Serial.read();
+          } while (!(((c >= '0') && (c <= '9')) || ((c >= 'A') && (c <= 'F'))));
+
+          value = value * 16 + hexToByte(c);
+          EEPROM.write(addr + i, value);
+        }
+        Serial.print("w:");
+        for (byte i = 0; i < 8; i++) {
+          value = EEPROM.read(addr + i);;
+          Serial.print(value, HEX);
+          if (i < 7) {
+            Serial.print(",");
+          }
+        }
+        Serial.println();
+        addr = addr + 8;
+      }
+      if (myChar == '*') {
+        endOfPrg = true;
+      }
+    }
+  }
+  Serial.println("end");
+  Serial.end();
+  doReset();
+}
+
+byte hexToByte (char c) {
+  if ( (c >= '0') && (c <= '9') ) {
+    return c - '0';
+  }
+  if ( (c >= 'A') && (c <= 'F') ) {
+    return (c - 'A') + 10;
+  }
 }