class

Dependencies:   RTC8563 mbed

Fork of rtc_class by Dani Hevi

Files at this revision

API Documentation at this revision

Comitter:
Hevi
Date:
Thu Apr 30 10:49:12 2015 +0000
Parent:
2:c3120898fc96
Commit message:
class2

Changed in this revision

RTC8563.cpp Show diff for this revision Revisions of this file
RTC8563.h Show diff for this revision Revisions of this file
RTC8563.lib Show annotated file Show diff for this revision Revisions of this file
const.h Show diff for this revision Revisions of this file
date.cpp Show annotated file Show diff for this revision Revisions of this file
date.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c3120898fc96 -r 0de441ee46ce RTC8563.cpp
--- a/RTC8563.cpp	Thu Apr 16 10:25:35 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,63 +0,0 @@
-//
-//  @ Project : RTC Date Time Clock
-//  @ File Name : RTC8563.cpp
-//  @ Date : 06.04.2015
-//  @ Author : Daniel Hevesy
-//  @ Copyright : daniel.hevesy-szetty@bulme.at
-//
- 
-#include "mbed.h"
-#include "const.h"
- 
-#include "RTC8563.h"
- 
-RTC8563::RTC8563() : i2c(p28, p27)  // delete void and add call to base constructor 
-{
-    // Initialise I2C
-    i2c.frequency(40000);              
-    char init1[2] = {0x6, 0x00};
-    char init2[2] = {0x7, 0xff};
-    i2c.write(0x40, init1, 2);
-    i2c.write(0x40, init2, 2);
-}
- 
-RTC8563::RTC8563(PinName sda, PinName scl) : i2c(sda, scl) 
-{
-   // Initialise I2C
-    i2c.frequency(40000);              
-    char init1[2] = {0x6, 0x00};
-    char init2[2] = {0x7, 0xff};
-    i2c.write(0x40, init1, 2);
-    i2c.write(0x40, init2, 2);
-}
- 
-char RTC8563::rtc_read(char address)
-{
-    char value;
-    i2c.start();
-    i2c.write(RTC8563_ADR);
-    i2c.write(address);
-    i2c.start();
-    i2c.write(RTC8563_ADR | _READ);
-    value = i2c.read(0);
-    i2c.stop();
- 
-    return value;
-}
- 
-void RTC8563::rtc_write(char address, char value)
-{
-    i2c.start();
-    i2c.write(RTC8563_ADR);
-    i2c.write(address);
-    i2c.write(value);
-    i2c.stop();
-}
- 
-void RTC8563::rtc_init()
-{
-}
- 
-void RTC8563::rtc_alarm()
-{
-}
diff -r c3120898fc96 -r 0de441ee46ce RTC8563.h
--- a/RTC8563.h	Thu Apr 16 10:25:35 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,27 +0,0 @@
-//
-//  @ Project : RTC8563
-//  @ File Name : RTC8563.h
-//  @ Date : 16.04.2015
-//  @ Author : Daniel Hevesy
-//  @ Copyright : daniel.hevesy-szetty@bulme.at
-//
-#include "mbed.h"
-#include "const.h"
- 
-#if !defined(_RTC8563_H)
-#define _RTC8563_H
- 
-class RTC8563
-{
-public:
-    RTC8563();          // delete void
-    RTC8563(PinName sda, PinName scl);
-    char rtc_read(char address);
-    void rtc_write(char address, char value);
-    void rtc_init();
-    void rtc_alarm();
-protected:
-    I2C i2c;
-};
- 
-#endif  //_RTC8563_H
\ No newline at end of file
diff -r c3120898fc96 -r 0de441ee46ce RTC8563.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/RTC8563.lib	Thu Apr 30 10:49:12 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/Hevi/code/RTC8563/#fe72feeab094
diff -r c3120898fc96 -r 0de441ee46ce const.h
--- a/const.h	Thu Apr 16 10:25:35 2015 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,36 +0,0 @@
-/***********************************
-name:   const.h    Version: 0.1
-//  @ Author : Daniel Hevesy
-//  @ Copyright : daniel.hevesy-szetty@bulme.at
-description:
-  Named constants definitions for registers 
-  PCF8563 RTC on HIMBED M0 - LPC11U24 
-***********************************/
- 
-#ifndef CONST_H
-#define CONST_H
- 
-// Address of RTC
-const int RTC8563_ADR = 0xA2;
-// Control and status
-const int CONTROL1 = 0x00;
-const int CONTROL2 = 0x01;
-// Time and date
-const int SECONDS = 0x02;   
-const int MINUTES = 0x03;
-const int HOURS = 0x04;
-const int DAYS = 0x05;
-const int WEEKDAYS = 0x06;
-const int MONTHS = 0x07;
-const int YEARS = 0x08;
-// Alarm
-const int MINUTE_ALARM = 0x09;
-const int HOUR_ALARM = 0x0A;
-const int DAY_ALARM = 0x0B;
-const int WEEKDAY_ALARM = 0x0C;
-// Clock and timer
-const int CLOCKOUT_FREQ = 0x0D;
-const int TIMER_CINTROL = 0x0E;
-const int _READ = 0x01;
- 
-#endif
\ No newline at end of file
diff -r c3120898fc96 -r 0de441ee46ce date.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/date.cpp	Thu Apr 30 10:49:12 2015 +0000
@@ -0,0 +1,15 @@
+#include "mbed.h"
+#include "const.h"
+#include "date.h"
+
+uint8_t Date::bcdToUint(uint8_t const nybbles)
+{
+    uint8_t result;
+    result = (nybbles>>4) *10 + (nybbles & 0x0F);
+    return result;
+}
+uint8_t Date::GetDay()
+{
+    uint8_t day = rtc_read(DAYS);
+    return bcdToUint(day & 0x3F);
+}
diff -r c3120898fc96 -r 0de441ee46ce date.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/date.h	Thu Apr 30 10:49:12 2015 +0000
@@ -0,0 +1,15 @@
+#include "mbed.h"
+#include "const.h"
+#include "RTC8563.h"
+
+#ifndef DATE_H
+#define DATE_H
+class Date : public RTC8563 
+{
+private:
+    uint8_t bcdToUint(uint8_t const nybbles);
+public:
+    uint8_t GetDay();
+};
+
+#endif
\ No newline at end of file
diff -r c3120898fc96 -r 0de441ee46ce main.cpp
--- a/main.cpp	Thu Apr 16 10:25:35 2015 +0000
+++ b/main.cpp	Thu Apr 30 10:49:12 2015 +0000
@@ -13,6 +13,7 @@
 #include "const.h"
 #include "RTC8563.h"
 #include "string"
+#include "date.h"
  
 Serial pc(USBTX, USBRX);
 //I2C i2c(p28, p27);
@@ -23,12 +24,14 @@
  
 int main()
 {
-    RTC8563 rtc;  // instanziieren des Objektes rtc
+    Date rtc;  // instanziieren des Objektes rtc
  
     pc.printf("Setting up RTC\n");
     //rtc.rtc_init();
  
     while(1) {
+        
+        pc.printf("_____Date: %i",rtc.GetDay());
         //printTime();           
         year = rtc.rtc_read(YEARS);   // Aufruf der Methode rtc_read der Instanz (Objekt) rtc
         month = rtc.rtc_read(MONTHS);