RTC8563

Dependents:   rtc_func Projekt_Wecker_LCD Projekt_Wecker_LCD Projekt_Wecker_LCD

Files at this revision

API Documentation at this revision

Comitter:
wolpra98
Date:
Thu Apr 30 10:12:13 2015 +0000
Parent:
0:9017c5d1bbb2
Commit message:
Alarm Clock with Lcd-Display

Changed in this revision

RTC8563.cpp Show annotated file Show diff for this revision Revisions of this file
RTC8563.h Show annotated file Show diff for this revision Revisions of this file
diff -r 9017c5d1bbb2 -r e84a6be5784c RTC8563.cpp
--- a/RTC8563.cpp	Thu Apr 16 10:35:00 2015 +0000
+++ b/RTC8563.cpp	Thu Apr 30 10:12:13 2015 +0000
@@ -5,32 +5,32 @@
 //  @ Author : Franz Pucher
 //  @ Copyright : pe@bulme.at
 //
- 
+
 #include "mbed.h"
 #include "const.h"
- 
+
 #include "RTC8563.h"
- 
-RTC8563::RTC8563() : i2c(p28, p27)  // delete void and add call to base constructor 
+
+RTC8563::RTC8563() : i2c(p28, p27)  // delete void and add call to base constructor
 {
     // Initialise I2C
-    i2c.frequency(40000);              
+    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) 
+
+RTC8563::RTC8563(PinName sda, PinName scl) : i2c(sda, scl)
 {
-   // Initialise I2C
-    i2c.frequency(40000);              
+    // 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;
@@ -41,10 +41,10 @@
     i2c.write(RTC8563_ADR | _READ);
     value = i2c.read(0);
     i2c.stop();
- 
+
     return value;
 }
- 
+
 void RTC8563::rtc_write(char address, char value)
 {
     i2c.start();
@@ -53,11 +53,37 @@
     i2c.write(value);
     i2c.stop();
 }
- 
+
 void RTC8563::rtc_init()
 {
+    rtc_write(CONTROL1, 0x20); //stop
+    rtc_write(CONTROL2, 0x00);
+    rtc_write(HOURS, 0x06);
+    rtc_write(MINUTES, 0x59);
+    rtc_write(SECONDS, 0x00);
+    rtc_write(WEEKDAYS, 0x05);
+    rtc_write(CLOCKOUT_FREQ, 0x00); // 0x83 = TE on & 1Hz
+    rtc_write(TIMER_CINTROL, 0x00);
+    rtc_write(CONTROL1, 0x00); //start
 }
- 
+
 void RTC8563::rtc_alarm()
 {
-}
\ No newline at end of file
+    rtc_write(CONTROL1, 0x20); //stop
+    rtc_write(CONTROL2, 0x02); // alarm AF alarm flag bit
+    rtc_write(DAY_ALARM, (0x80) );
+    rtc_write(HOUR_ALARM, (0x07));
+    rtc_write(MINUTE_ALARM, (0x05));
+    rtc_write(WEEKDAY_ALARM, (0x80));
+    rtc_write(CONTROL1, 0x00); //start
+}
+void RTC8563::rtc_alarm(int hour, int min)
+{
+    rtc_write(CONTROL1, 0x20); //stop
+    rtc_write(CONTROL2, 0x02); // alarm AF alarm flag bit
+    rtc_write(DAY_ALARM, (0x80) );
+    rtc_write(HOUR_ALARM, (hour));
+    rtc_write(MINUTE_ALARM, (min));
+    rtc_write(WEEKDAY_ALARM, (0x80));
+    rtc_write(CONTROL1, 0x00); //start
+}
diff -r 9017c5d1bbb2 -r e84a6be5784c RTC8563.h
--- a/RTC8563.h	Thu Apr 16 10:35:00 2015 +0000
+++ b/RTC8563.h	Thu Apr 30 10:12:13 2015 +0000
@@ -20,6 +20,7 @@
     void rtc_write(char address, char value);
     void rtc_init();
     void rtc_alarm();
+    void rtc_alarm(int hour, int min);
 protected:
     I2C i2c;
 };