diff --git a/ER1400.cpp b/ER1400.cpp index e25d961..116de90 100644 --- a/ER1400.cpp +++ b/ER1400.cpp @@ -1,12 +1,15 @@ -/*! - ER1400.cpp - - v20210423: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: ER1400.cpp + *************************************/ #include "ER1400.h" -ER1400::ER1400(uint8_t clockPin, uint8_t c1Pin, uint8_t c2Pin, uint8_t c3Pin, uint8_t outPin, uint8_t inPin) { +// ER1400 +ER1400::ER1400(uint8_t clockPin, uint8_t c1Pin, uint8_t c2Pin, uint8_t c3Pin, uint8_t outPin, uint8_t inPin) +{ this->clockPin = clockPin; this->c1Pin = c1Pin; this->c2Pin = c2Pin; @@ -16,7 +19,9 @@ ER1400::ER1400(uint8_t clockPin, uint8_t c1Pin, uint8_t c2Pin, uint8_t c3Pin, ui init(); } -void ER1400::init() { +// init +void ER1400::init() +{ digitalWrite(clockPin, 0); digitalWrite(c1Pin, 0); digitalWrite(c2Pin, 0); @@ -30,24 +35,26 @@ void ER1400::init() { pinMode(outPin, OUTPUT); } -//readData -int ER1400::readData(int adr) { - acceptAddress (adr); +// readData (acceptAddress -> read -> shiftDataOut) +int ER1400::readData(int adr) +{ + acceptAddress(adr); read(); return shiftDataOut(); } -//writeData -void ER1400::writeData(int adr, int data) { +// writeData (acceptAddress -> erase -> acceptData -> write) +void ER1400::writeData(int adr, int data) +{ acceptAddress(adr); erase(); acceptData(data); write(); } - // STANDBY (C1: 0, C2: 0, C3: 0) -void ER1400::standby() { +void ER1400::standby() +{ digitalWrite(clockPin, 0); digitalWrite(c1Pin, 0); digitalWrite(c2Pin, 0); @@ -59,13 +66,15 @@ void ER1400::standby() { } // ACCEPT ADDRESS (C1: 0, C2: 1, C3: 1) -void ER1400::acceptAddress(int adr) { - i; +void ER1400::acceptAddress(int adr) +{ + i; adr1 = 1 << (adr / 10); adr2 = 1 << (adr % 10); - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) + { digitalWrite(clockPin, 0); digitalWrite(c1Pin, 0); digitalWrite(c2Pin, 1); @@ -75,7 +84,8 @@ void ER1400::acceptAddress(int adr) { digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); } - for (i = 0; i < 10; i++) { + for (i = 0; i < 10; i++) + { digitalWrite(clockPin, 0); digitalWrite(c1Pin, 0); digitalWrite(c2Pin, 1); @@ -85,12 +95,13 @@ void ER1400::acceptAddress(int adr) { digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); } - - standby(); + + standby(); } // READ (C1: 1, C2: 0, C3: 0) -void ER1400::read() { +void ER1400::read() +{ digitalWrite(clockPin, 0); digitalWrite(c1Pin, 1); digitalWrite(c2Pin, 0); @@ -99,16 +110,18 @@ void ER1400::read() { delayMicroseconds(delayvalue); digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); - - standby(); + + standby(); } // SHIFT DATA OUT (C1: 1, C2: 0, C3: 1) -int ER1400::shiftDataOut() { +int ER1400::shiftDataOut() +{ x = 0; y = 0; - for (i = 0; i < 14; i++) { + for (i = 0; i < 14; i++) + { digitalWrite(clockPin, 0); digitalWrite(c1Pin, 1); digitalWrite(c2Pin, 0); @@ -122,13 +135,14 @@ int ER1400::shiftDataOut() { delayMicroseconds(delayvalue); } - standby(); - - return x; + standby(); + + return x; } // ERASE (C1: 0, C2: 1, C3: 0) -void ER1400::erase() { +void ER1400::erase() +{ digitalWrite(clockPin, 0); digitalWrite(c1Pin, 0); digitalWrite(c2Pin, 1); @@ -137,16 +151,15 @@ void ER1400::erase() { delayMicroseconds(delayvalue); digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); - - standby(); + + standby(); } // ACCEPT DATA (C1: 1, C2: 1, C3: 1) -void ER1400::acceptData(int data) { - x = 0; - y = 0; - - for (i = 0; i < 14; i++) { +void ER1400::acceptData(int data) +{ + for (i = 0; i < 14; i++) + { digitalWrite(clockPin, 0); digitalWrite(c1Pin, 1); digitalWrite(c2Pin, 1); @@ -156,12 +169,13 @@ void ER1400::acceptData(int data) { digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); } - - standby(); + + standby(); } // WRITE (C1: 1, C2: 1, C3: 0) -void ER1400::write() { +void ER1400::write() +{ digitalWrite(clockPin, 0); digitalWrite(c1Pin, 1); digitalWrite(c2Pin, 1); @@ -170,6 +184,6 @@ void ER1400::write() { delayMicroseconds(delayvalue); digitalWrite(clockPin, 1); delayMicroseconds(delayvalue); - - standby(); + + standby(); } diff --git a/ER1400.h b/ER1400.h index 4b03985..e479a84 100644 --- a/ER1400.h +++ b/ER1400.h @@ -1,56 +1,57 @@ -/*! - ER1400.h - - v20210423: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: ER1400.h + *************************************/ #ifndef ER1400_H #define ER1400_H #include -class ER1400 { +class ER1400 +{ - private: - uint8_t clockPin; - uint8_t c1Pin; - uint8_t c2Pin; - uint8_t c3Pin; - uint8_t outPin; - uint8_t inPin; - int data; - int adr; - const int delayvalue = 25; - int adr1; - int adr2; - int x; - int y; - uint8_t i; +private: + uint8_t clockPin; + uint8_t c1Pin; + uint8_t c2Pin; + uint8_t c3Pin; + uint8_t outPin; + uint8_t inPin; + int data; + int adr; + const int delayvalue = 25; + int adr1; + int adr2; + int x; + int y; + uint8_t i; - public: - ER1400(uint8_t clockPin, uint8_t c1Pin, uint8_t c2Pin, uint8_t c3Pin, uint8_t outPin, uint8_t inPin); - void init(); +public: + ER1400(uint8_t clockPin, uint8_t c1Pin, uint8_t c2Pin, uint8_t c3Pin, uint8_t outPin, uint8_t inPin); + void init(); - // readData (acceptAddress -> read -> shiftDataOut) - int readData(int adr); - // writeData (acceptAddress -> erase -> acceptData -> write) - void writeData(int adr, int data); - - // STANDBY (C1: 0, C2: 0, C3: 0) - void standby(); - // ACCEPT ADDRESS (C1: 0, C2: 1, C3: 1) - void acceptAddress(int adr); - // READ (C1: 1, C2: 0, C3: 0) - void read(); - // SHIFT DATA OUT (C1: 1, C2: 0, C3: 1) - int shiftDataOut(); - // ERASE (C1: 0, C2: 1, C3: 0) - void erase(); - // ACCEPT DATA (C1: 1, C2: 1, C3: 1) - void acceptData(int data); - // WRITE (C1: 1, C2: 1, C3: 0) - void write(); - // NOT USED (C1: 0, C2: 0, C3: 1) + // readData (acceptAddress -> read -> shiftDataOut) + int readData(int adr); + // writeData (acceptAddress -> erase -> acceptData -> write) + void writeData(int adr, int data); + // STANDBY (C1: 0, C2: 0, C3: 0) + void standby(); + // ACCEPT ADDRESS (C1: 0, C2: 1, C3: 1) + void acceptAddress(int adr); + // READ (C1: 1, C2: 0, C3: 0) + void read(); + // SHIFT DATA OUT (C1: 1, C2: 0, C3: 1) + int shiftDataOut(); + // ERASE (C1: 0, C2: 1, C3: 0) + void erase(); + // ACCEPT DATA (C1: 1, C2: 1, C3: 1) + void acceptData(int data); + // WRITE (C1: 1, C2: 1, C3: 0) + void write(); + // NOT USED (C1: 0, C2: 0, C3: 1) }; -#endif \ No newline at end of file +#endif diff --git a/examples/erase/erase.ino b/examples/erase/erase.ino index 76f15bf..9a3f433 100644 --- a/examples/erase/erase.ino +++ b/examples/erase/erase.ino @@ -1,28 +1,35 @@ -/*! - erase.ino - - v20210423: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: erase.ino + *************************************/ #include - #include + #define PIN_CLK 2 #define PIN_C1 3 #define PIN_C2 4 #define PIN_C3 5 #define PIN_OUT 6 #define PIN_IN 7 + ER1400 er1400(PIN_CLK, PIN_C1, PIN_C2, PIN_C3, PIN_OUT, PIN_IN); -void setup() { +void setup() +{ int i; - for (i = 0; i < 100; i++) { + // Loop through the 100 positions of the ER1400 + for (i = 0; i < 100; i++) + { + // Erease the information on position i er1400.acceptAddress(i); er1400.erase(); er1400.write(); } } -void loop() { +void loop() +{ } diff --git a/examples/retention_update/retention_update.ino b/examples/retention_update/retention_update.ino index c3bc6e0..3ffaa33 100644 --- a/examples/retention_update/retention_update.ino +++ b/examples/retention_update/retention_update.ino @@ -1,39 +1,47 @@ -/*! - retention_update.ino - - v20210424: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: retention_update.ino + *************************************/ #include - #include + #define PIN_CLK 2 #define PIN_C1 3 #define PIN_C2 4 #define PIN_C3 5 #define PIN_OUT 6 #define PIN_IN 7 + ER1400 er1400(PIN_CLK, PIN_C1, PIN_C2, PIN_C3, PIN_OUT, PIN_IN); String command; int i; -void setup() { +void setup() +{ Serial.begin(9600); Serial.println("Before:"); char j[4]; char dataOut[4]; - for (i = 0; i < 100; i++) { - if ( (i % 8) == 0) { + for (i = 0; i < 100; i++) + { + if ((i % 8) == 0) + { sprintf(j, "%04X", i); Serial.print(j); Serial.print(": "); } sprintf(dataOut, "%04X", er1400.readData(i), HEX); Serial.print(dataOut); - if ( ( (i + 1) % 8) == 0) { + if (((i + 1) % 8) == 0) + { Serial.println(""); - } else { + } + else + { Serial.print(" "); } } @@ -42,13 +50,17 @@ void setup() { Serial.println("Send \"update\" (lowercase) to update the retention."); } -void loop() { - if (Serial.available()) { +void loop() +{ + if (Serial.available()) + { command = Serial.readStringUntil('\n'); - if (command.equals("update")) { + if (command.equals("update")) + { Serial.println(""); int data; - for (i = 0; i < 100; i++) { + for (i = 0; i < 100; i++) + { data = er1400.readData(i); er1400.writeData(i, data); } @@ -56,17 +68,22 @@ void loop() { int i; char j[4]; char dataOut[4]; - for (i = 0; i < 100; i++) { - if ( (i % 8) == 0) { + for (i = 0; i < 100; i++) + { + if ((i % 8) == 0) + { sprintf(j, "%04X", i); Serial.print(j); Serial.print(": "); } sprintf(dataOut, "%04X", er1400.readData(i), HEX); Serial.print(dataOut); - if ( ( (i + 1) % 8) == 0) { + if (((i + 1) % 8) == 0) + { Serial.println(""); - } else { + } + else + { Serial.print(" "); } } diff --git a/examples/serial_output/serial_output.ino b/examples/serial_output/serial_output.ino index befd856..8173268 100644 --- a/examples/serial_output/serial_output.ino +++ b/examples/serial_output/serial_output.ino @@ -1,30 +1,35 @@ -/*! - serial_output.ino - - v20210423: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: serial_output.ino + *************************************/ #include - #include + #define PIN_CLK 2 #define PIN_C1 3 #define PIN_C2 4 #define PIN_C3 5 #define PIN_OUT 6 #define PIN_IN 7 + ER1400 er1400(PIN_CLK, PIN_C1, PIN_C2, PIN_C3, PIN_OUT, PIN_IN); -void setup() { +void setup() +{ Serial.begin(9600); int i; char dataOut[4]; - for (i = 0; i < 100; i++) { + for (i = 0; i < 100; i++) + { sprintf(dataOut, "%04X", er1400.readData(i), HEX); Serial.print(dataOut); } Serial.println(""); } -void loop() { +void loop() +{ } diff --git a/examples/serial_output_readable/serial_output_readable.ino b/examples/serial_output_readable/serial_output_readable.ino index a3726f8..fa45b27 100644 --- a/examples/serial_output_readable/serial_output_readable.ino +++ b/examples/serial_output_readable/serial_output_readable.ino @@ -1,42 +1,50 @@ -/*! - serial_output_readable.ino - - v20210423: Initial version - v20210424: 0x0000 reading shown as 0000 instead of 0 -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: serial_output_readable.ino + *************************************/ #include - #include + #define PIN_CLK 2 #define PIN_C1 3 #define PIN_C2 4 #define PIN_C3 5 #define PIN_OUT 6 #define PIN_IN 7 + ER1400 er1400(PIN_CLK, PIN_C1, PIN_C2, PIN_C3, PIN_OUT, PIN_IN); -void setup() { +void setup() +{ Serial.begin(9600); int i; char j[4]; char dataOut[4]; - for (i = 0; i < 100; i++) { - if ( (i % 8) == 0) { + for (i = 0; i < 100; i++) + { + if ((i % 8) == 0) + { sprintf(j, "%04X", i); Serial.print(j); Serial.print(": "); } sprintf(dataOut, "%04X", er1400.readData(i), HEX); Serial.print(dataOut); - if ( ( (i + 1) % 8) == 0) { + if (((i + 1) % 8) == 0) + { Serial.println(""); - } else { + } + else + { Serial.print(" "); } } Serial.println(""); } -void loop() { +void loop() +{ } diff --git a/examples/write/write.ino b/examples/write/write.ino index 0e466a6..6bee426 100644 --- a/examples/write/write.ino +++ b/examples/write/write.ino @@ -1,24 +1,28 @@ -/*! - write.ino - - v20210423: Initial version -*/ +/************************************* + * arduino-library-er1400 + * Author: Michel Bats + * Website: www.batssoft.nl + * File name: write.ino + *************************************/ #include - #include + #define PIN_CLK 2 #define PIN_C1 3 #define PIN_C2 4 #define PIN_C3 5 #define PIN_OUT 6 #define PIN_IN 7 + ER1400 er1400(PIN_CLK, PIN_C1, PIN_C2, PIN_C3, PIN_OUT, PIN_IN); -void setup() { +void setup() +{ er1400.writeData(26, 0x1DD2); er1400.writeData(36, 0x2ADA); } -void loop() { +void loop() +{ }