Permalink
Browse files

added 022

  • Loading branch information...
1 parent 6c4e34b commit db17f22582e2f8780e13a852c11d28c8cc36932d @zevenrodriguez zevenrodriguez committed Nov 1, 2011
Showing with 63 additions and 2 deletions.
  1. +63 −2 RTClib.cpp
View
@@ -4,13 +4,22 @@
#include <Wire.h>
#include <avr/pgmspace.h>
#include "RTClib.h"
-#include <arduino.h>
#define DS1307_ADDRESS 0x68
#define SECONDS_PER_DAY 86400L
#define SECONDS_FROM_1970_TO_2000 946684800
-int i = 0;
+
+#if ARDUINO > 22
+#include <arduino.h>
+#endif
+
+#if ARDUINO <= 22
+#include <WProgram.h>
+#endif
+
+
+int i = 0; //The new wire library needs to take an int when you are sending for the zero register
////////////////////////////////////////////////////////////////////////////////
// utility code, some of this could be exposed in the DateTime API if needed
@@ -128,6 +137,10 @@ uint8_t RTC_DS1307::begin(void) {
return 1;
}
+
+#if ARDUINO > 22
+
+
uint8_t RTC_DS1307::isrunning(void) {
Wire.beginTransmission(DS1307_ADDRESS);
Wire.write(i);
@@ -169,6 +182,54 @@ DateTime RTC_DS1307::now() {
return DateTime (y, m, d, hh, mm, ss);
}
+#endif
+
+#if ARDUINO < 22
+
+uint8_t RTC_DS1307::isrunning(void) {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.send(i);
+ Wire.endTransmission();
+
+ Wire.requestFrom(DS1307_ADDRESS, 1);
+ uint8_t ss = Wire.read();
+ return !(ss>>7);
+}
+
+void RTC_DS1307::adjust(const DateTime& dt) {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.send(i);
+ Wire.send(bin2bcd(dt.second()));
+ Wire.send(bin2bcd(dt.minute()));
+ Wire.send(bin2bcd(dt.hour()));
+ Wire.send(bin2bcd(0));
+ Wire.send(bin2bcd(dt.day()));
+ Wire.send(bin2bcd(dt.month()));
+ Wire.send(bin2bcd(dt.year() - 2000));
+ Wire.send(i);
+ Wire.endTransmission();
+}
+
+DateTime RTC_DS1307::now() {
+ Wire.beginTransmission(DS1307_ADDRESS);
+ Wire.send(i);
+ Wire.endTransmission();
+
+ Wire.requestFrom(DS1307_ADDRESS, 7);
+ uint8_t ss = bcd2bin(Wire.receive() & 0x7F);
+ uint8_t mm = bcd2bin(Wire.receive());
+ uint8_t hh = bcd2bin(Wire.receive());
+ Wire.read();
+ uint8_t d = bcd2bin(Wire.receive());
+ uint8_t m = bcd2bin(Wire.receive());
+ uint16_t y = bcd2bin(Wire.receive()) + 2000;
+
+ return DateTime (y, m, d, hh, mm, ss);
+}
+
+#endif
+
+
////////////////////////////////////////////////////////////////////////////////
// RTC_Millis implementation

0 comments on commit db17f22

Please sign in to comment.