Working Version of the Real Time Clock module DS1307.

Dependents:   Rtc_Ds1307_Sample TAREA_5_PROCESADORES Rtc_Ds1307_lcd_alarma Rtc_Ds1307_Reloj_con_alarma_aplazable ... more

This is my implementation of the DS1307.

I plan to add functionality which will make use of the OSC Input and which will increment the time continuously. A query to the module will then only have to be made when the MBED has been powered down.

Files at this revision

API Documentation at this revision

Comitter:
leihen
Date:
Sun Jun 23 18:26:47 2013 +0000
Parent:
5:30531f2121a2
Child:
7:dca20be3ef38
Commit message:
rewritten the Header due to some strange error while compiling.

Changed in this revision

RtcCls.c Show annotated file Show diff for this revision Revisions of this file
RtcCls.h Show annotated file Show diff for this revision Revisions of this file
Rtc_Ds1307.h Show annotated file Show diff for this revision Revisions of this file
--- a/RtcCls.c	Sun Jun 23 17:02:21 2013 +0000
+++ b/RtcCls.c	Sun Jun 23 18:26:47 2013 +0000
@@ -1,9 +1,8 @@
-
+#include "mbed.h"
 #include "RtcCls.h"
 
 
 
-
 RtcCls::RtcCls(PinName sda, PinName scl, PinName sqw, bool bUseSqw)
     : Rtc_Ds1307(sda, scl), m_sqw(sqw), m_bUseSqw(bUseSqw), m_bAlarmEnabled(false), m_alarmfunc(NULL)
 {
@@ -60,4 +59,4 @@
     tim.wday = now->tm_wday +1;
 
     setTime( tim, true, true);
-}
\ No newline at end of file
+}
--- a/RtcCls.h	Sun Jun 23 17:02:21 2013 +0000
+++ b/RtcCls.h	Sun Jun 23 18:26:47 2013 +0000
@@ -1,36 +1,60 @@
-#ifndef __DAMNFILEHEADER__
-#define __DAMNFILEHEADER__
+/* RtcCls.h */
+/*
+Copyright (c) 2013 Henry Leinen (henry[dot]leinen [at] online [dot] de)
+ 
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+ 
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+ 
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+THE SOFTWARE.
+*/
+#ifndef __RTCCLS_H__
+#define __RTCCLS_H__
 
 
 #include "Rtc_Ds1307.h"
 
-typedef void (*callback_t)(void);
+typedef void (*RtcCallback_t) (void);
 
-class RtcCls   :   public Rtc_Ds1307
+
+class RtcCls : public Rtc_Ds1307
 {
 protected:
-//    InterruptIn         m_sqw;
-    bool                m_bUseSqw;
-    time_t              m_time;             //  Only used in case of SQW use
-
-    bool                m_bAlarmEnabled;
-    callback_t          m_alarmfunc;
-    time_t              m_alarmTime;
-
+    InterruptIn                 m_sqw;
+    bool                        m_bUseSqw;
+    time_t                      m_time;             //  Only used in case SQW is used
+    
+    bool                        m_bAlarmEnabled;
+    RtcCallback_t               m_alarmfunc;
+    time_t                      m_alarmTime;
+    
 public:
     RtcCls(PinName sda, PinName scl, PinName sqw, bool bUseSqw);
-
+    
 protected:
     static void _callback(void);
-
+    
 public:
-    time_t              getTime();
-    void                setTime(time_t t);
+    time_t                      getTime();
+    void                        setTime(time_t t);
 public:
-    void                setAlarm(int nSeconds, callback_t alarmfunc) {
+    void                        setAlarm(int nSeconds, RtcCallback_t alarmfunc) {
         m_alarmfunc = alarmfunc;
         m_alarmTime = m_time + nSeconds;
         m_bAlarmEnabled = (alarmfunc == NULL) ? false : true;
     }
 };
-#endif //   __RTC_CLS_H__
+
+#endif //   __RTCCLS_H__
\ No newline at end of file
--- a/Rtc_Ds1307.h	Sun Jun 23 17:02:21 2013 +0000
+++ b/Rtc_Ds1307.h	Sun Jun 23 18:26:47 2013 +0000
@@ -24,6 +24,15 @@
 #define __RTC_DS1307_H__
 
 
+/** Class Rtc_Ds1307 implements the real time clock module DS1307
+ *
+ * You can read the clock and set a new time and date.
+ * It is also possible to start and stop the clock.
+ * Rtc_Ds1307 allows you to display the time in a 12h or 24h format
+ */
+class Rtc_Ds1307
+{
+
 /** Structure which is used to exchange the time and date
  */
 typedef struct {
@@ -44,15 +53,6 @@
     RS8kHz = 2,
     RS32kHz = 3
 } SqwRateSelect_t;
-
-/** Class Rtc_Ds1307 implements the real time clock module DS1307
- *
- * You can read the clock and set a new time and date.
- * It is also possible to start and stop the clock.
- * Rtc_Ds1307 allows you to display the time in a 12h or 24h format
- */
-class Rtc_Ds1307
-{
         I2C*    m_rtc;
         
         static const char *m_weekDays[];    
@@ -75,7 +75,7 @@
          *
          * @returns true if successful, otherwise an acknowledge error occured
          */
-        bool getTime(Time_rtc& time);
+        virtual bool getTime(Time_rtc& time);
         
         /** Write the given time onto the RTC chip
          *
@@ -87,7 +87,7 @@
          *
          * @returns true if successful, otherwise an acknowledge error occured
          */
-        bool setTime(Time_rtc& time, bool start, bool thm);        
+        virtual bool setTime(Time_rtc& time, bool start, bool thm);        
         
         /** Start the clock. Please note that the seconds register need to be read and
          * written in order to start or stop the clock. This can lead to an error
@@ -139,6 +139,4 @@
 
 
 };
-        
-
 #endif // __RTC_DS1307_H__
\ No newline at end of file