Display the date and time on text LCD using RTC DS1307.

Dependencies:   DS1307 TextLCD mbed

Files at this revision

API Documentation at this revision

Comitter:
ertech_pl
Date:
Fri Dec 26 11:22:36 2014 +0000
Parent:
0:bad75bd13618
Commit message:
compilation of txt lcd & RTC DS1307 demo

Changed in this revision

DS1307.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DS1307.lib	Fri Dec 26 11:22:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/harrypowers/code/DS1307/#c3e4da8feb10
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Fri Dec 26 11:22:36 2014 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/simon/code/TextLCD/#e4cb7ddee0d3
--- a/main.cpp	Fri Feb 21 10:00:46 2014 +0000
+++ b/main.cpp	Fri Dec 26 11:22:36 2014 +0000
@@ -1,26 +1,77 @@
 #include "mbed.h"
-
-DigitalOut myled(LED1);
+#include "ds1307.h"
+#include "TextLCD.h"
 
-int main() {
-    
-    printf("RTC example\n"); 
-    set_time(1387188323); // Set RTC time to 16 December 2013 10:05:23 UTC
-    printf("Date and time are set.\n");
+TextLCD lcd(D8, D9, D4, D5, D6, D7); // rs, e, d4-d7
+DS1307 my_tm(D14, D15); //sda, scl
+DigitalOut myled(LED1); // blinking LED
+InterruptIn mybutton(USER_BUTTON);  // user button (blue)
 
-    while(1) {
+int year, month, day, hour, min, sec, dw; // dw - day of week
+float delay=1.0; // delay time
+float showtime=0.0;
 
-        time_t seconds = time(NULL);
-
-        //printf("Time as seconds since January 1, 1970 = %d\n", seconds);
-        
-        printf("Time as a basic string = %s", ctime(&seconds));
+void lcdPrintDate(int row)
+{
+    lcd.locate(0, row);
+    lcd.printf("Data :");
+    lcd.locate(6, row);
+    lcd.printf("%02d", day);
+    lcd.printf("-");
+    lcd.printf("%02d", month);
+    lcd.printf("-");
+    lcd.printf("%04d", 2000+year);
+}
 
-        //char buffer[32];
-        //strftime(buffer, 32, "%I:%M:%S %p\n", localtime(&seconds));
-        //printf("Time as a custom formatted string = %s", buffer);
+void lcdPrintTime(int row)
+{
+    lcd.locate(0, row);
+    lcd.printf("Czas :");
+    lcd.locate(6, row);
+    lcd.printf("%02d", hour);
+    lcd.printf(":");
+    lcd.printf("%02d", min);
+    lcd.printf(":");
+    lcd.printf("%02d", sec);
+}
 
-        myled = !myled;      
-        wait(1);
+void pressed()
+{
+    if (delay == 1.0)
+    {
+        delay = 0.5; // 500 ms
+    }
+    else
+    {
+        delay = 1.0; // 1 sec
+        lcd.cls();
     }
 }
+
+
+
+int main() 
+{
+    lcd.cls();
+    my_tm.twentyfour_hour();
+    mybutton.fall(&pressed);
+    while (1) 
+    {
+        myled = !myled;
+        if (delay == 0.5)
+        {
+            my_tm.gettime(&sec, &min, &hour, &dw, &day, &month, &year);
+            lcdPrintDate(0);
+            lcdPrintTime(1);
+            showtime = showtime + delay;
+            if (showtime > 10)  // after 10 s sleep
+            {
+                showtime = 0.0;
+                delay = 1.0;
+                lcd.cls();
+            }
+        }
+        wait(delay);
+    }
+
+}
--- a/mbed.bld	Fri Feb 21 10:00:46 2014 +0000
+++ b/mbed.bld	Fri Dec 26 11:22:36 2014 +0000
@@ -1,1 +1,1 @@
-http://mbed.org/users/mbed_official/code/mbed/builds/ed8466a608b4
\ No newline at end of file
+http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5
\ No newline at end of file