This is the REAL TIME CLOCK for LPC1768

Dependencies:   TextLCD mbed

Fork of clock by masa miya

This code is for RTC of LPC1768. To give the value of year , one needs to substruct 1900 from the present year.

Files at this revision

API Documentation at this revision

Comitter:
tadns
Date:
Tue Apr 09 13:22:38 2013 +0000
Parent:
0:11c4cf24f38b
Commit message:
RTC clock for LPC 1768

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r 11c4cf24f38b -r 63e1320ed4f8 main.cpp
--- a/main.cpp	Mon Apr 18 05:58:23 2011 +0000
+++ b/main.cpp	Tue Apr 09 13:22:38 2013 +0000
@@ -1,34 +1,43 @@
-/* I made a clock in mbed. mbed has RTC built-in. 
-A convenient function is prepared for in the rtc_time 
-function group of mbed.h. Because data are provided 
-at the time when they give unix timestamp and ask it 
-at suitable distance, a format to like it can be set 
-and displays it to LCD. If unix timestamp is provided 
-from web, it becomes more convenient.
-*/
 #include "mbed.h"
 #include "TextLCD.h"
 
 TextLCD lcd(p24, p26, p27, p28, p29, p30);
-int offset_JAPAN = 32400;
 
 int main() {
-    set_time(1303099200+offset_JAPAN);  // Set RTC time to Mon, 18 Apr 2011 13:00:00
+     // setup time structure for Wed, 11 April 2013 5:00:00
+    struct tm t;
+    t.tm_sec = 00;    // 0-59
+    t.tm_min = 00;    // 0-59
+    t.tm_hour = 5;   // 0-23
+    t.tm_mday = 11;   // 1-31
+    t.tm_mon = 3;     // 0-11
+    t.tm_year = 113;  // year since 1900
 
-    lcd.cls();    
-    while(1) {
+    // convert to timestamp 
+    time_t seconds = mktime(&t);
+   
+  // Set RTC time today
+  set_time(mktime(&t));
+ 
+   while(1) {
+    
         time_t seconds = time(NULL);
 
-        lcd.locate(0,0);
-        char day[16];
-        strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds));
-        lcd.printf("%s", day);
-        
-        char time[16];
-        strftime(time, 16, "%H:%M:%S\n", localtime(&seconds));
-        lcd.locate(0,1);
-        lcd.printf("%s", time);
-
+       lcd.locate(0,0);
+      char day[16];
+      strftime(day, 16, "%Y/%m/%d %a\n", localtime(&seconds));
+      lcd.printf("%s", day);          
+               
+      char time[16];
+     strftime(time, 16, "%H:%M:%S\n", localtime(&seconds));
+     lcd.locate(0,1);
+      lcd.printf("%s", time);
+          
+          
         wait(1.0);
-    }
+   }
+    
+      
+  
+   
 }