Clock

Dependencies:   DS1307 Grove_Serial_LCD mbed

Files at this revision

API Documentation at this revision

Comitter:
yihui
Date:
Mon Dec 09 08:46:52 2013 +0000
Commit message:
initial

Changed in this revision

Grove_RTC.lib Show annotated file Show diff for this revision Revisions of this file
Grove_Serial_LCD.lib 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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 06a98b973b14 Grove_RTC.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Grove_RTC.lib	Mon Dec 09 08:46:52 2013 +0000
@@ -0,0 +1,1 @@
+https://mbed.org/users/harrypowers/code/DS1307/#c3e4da8feb10
diff -r 000000000000 -r 06a98b973b14 Grove_Serial_LCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Grove_Serial_LCD.lib	Mon Dec 09 08:46:52 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/seeed/code/Grove_Serial_LCD/#a166e203e4cf
diff -r 000000000000 -r 06a98b973b14 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Dec 09 08:46:52 2013 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "SerialLCD.h"
+#include "ds1307.h"
+ 
+SerialLCD lcd(P1_13, P1_14);  // Grove Serial LCD is connected to UART Tx and Rx pins
+DS1307 rtc(P0_5, P0_4);    // Grove RTC is connected to I2C SDA(P0_5) and SCL(P0_4)
+ 
+int main() {
+    const char *week[] = {"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"};
+    int sec, min, hour, day, date, month, year;
+    char strBuffer[16];
+    
+    lcd.begin();
+    lcd.print("Clock");
+    rtc.start_clock();
+    rtc.gettime(&sec, &min, &hour, &day, &date, &month, &year);
+    if (0 == year) {
+        rtc.settime(0, 0, 0, 4, 1, 1, 2014 % 100); // Jan 1st, 2014, Wed, 00:00:00
+    }
+
+    while(1) {
+        rtc.gettime(&sec, &min, &hour, &day, &date, &month, &year);
+        snprintf(strBuffer, sizeof(strBuffer), "%d-%d-%d  %s", 2000 + year, month, date, week[day]);
+        lcd.setCursor(0, 0);
+        lcd.print(strBuffer);
+        snprintf(strBuffer, sizeof(strBuffer), "%d:%d:%d", hour, min, sec);
+        lcd.setCursor(0, 1);
+        lcd.print(strBuffer);
+        wait(0.5);
+    }
+}
+
+
diff -r 000000000000 -r 06a98b973b14 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Dec 09 08:46:52 2013 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/a9913a65894f
\ No newline at end of file