Dependencies:   DS1307 mbed

Fork of RTC_test_ds1307 by Cellular building monitoring

Files at this revision

API Documentation at this revision

Comitter:
mathieusab
Date:
Thu Dec 01 16:31:04 2016 +0000
Parent:
1:b9b861f14c76
Commit message:
pour olivier

Changed in this revision

main_rtc.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r b9b861f14c76 -r fd30a7165b68 main_rtc.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main_rtc.cpp	Thu Dec 01 16:31:04 2016 +0000
@@ -0,0 +1,50 @@
+#include "ds1307.h"
+#include "mbed.h"
+//#include "USBSerial.h"
+
+#define SDA    PA_14
+#define SCL    PA_13
+
+Serial pc(USBTX, USBRX);
+
+DS1307 rtc(SDA,SCL); // start DS1307 class and give it pins for connections of the DS1307 device
+
+int sec = 10;       // 24 ssec
+int min = 43;       // 12 min
+int hours = 17;     // 8 pm
+int day = 7;        // Friday
+int date = 13;      // April 17
+int month = 11;
+int year = 2016;      // 2025
+                   // set time to these values on the ds1307 connected device
+
+//DigitalOut POWER(P1_3); //drive low to activate pins
+
+int main() {
+    
+     //POWER.write(1);
+     
+        pc.printf("Enter the date (day 0..31)");
+        pc.scanf("%d", &date);
+        pc.printf("Enter the date (month 1..12)");
+        pc.scanf("%d", &month);
+        pc.printf("Enter the date (year)");
+        pc.scanf("%d", &year);
+        pc.printf("Enter the time (hours 0..23)");
+        pc.scanf("%d", &hours);
+        pc.printf("Enter the time (minutes 0..59)");
+        pc.scanf("%d", &min);
+        pc.printf("Enter the time (seconds 0..59)");
+        pc.scanf("%d", &sec);
+    
+     rtc.settime( sec, min, hours, day, date, month, year);
+     
+     while(1){
+         
+     rtc.gettime( &sec, &min, &hours, &day, &date, &month, &year);
+     
+     pc.printf("%.2d/%.2d/%.4d %.1d %.2d:%.2d:%.2d\r\n", date, month, year, day, hours,min,sec);
+     
+     wait(3);
+     }
+ }
\ No newline at end of file