FRDM-KL46Z clock based on Paul Staron's FRDM-KL46Z-LCD-rtc-demo. Uses the on-board touch slider to set hours, minutes and seconds.

Dependencies:   SLCD TSI mbed-src

Fork of FRDM-KL46Z LCD rtc Demo by Paul Staron

After the instructions have finished scrolling across the LCD, press SW3 to cycle between, SET_HOURS, SET_MINUTES, SET_SECONDS and SHOW_TIME modes.

In (e.g.) SET_HOURS mode, press the capacitive touch slider (TSI), releasing when the LCD shows the correct hour (24H clock).

Files at this revision

API Documentation at this revision

Comitter:
star297
Date:
Mon Jan 27 21:58:45 2014 +0000
Parent:
0:4f67859595b2
Child:
2:46d52fa160b2
Commit message:
colon/dot function fixed in library, changed code to suit.

Changed in this revision

SLCD.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
--- a/SLCD.lib	Mon Jan 20 21:08:57 2014 +0000
+++ b/SLCD.lib	Mon Jan 27 21:58:45 2014 +0000
@@ -1,1 +1,1 @@
-https://mbed.org/users/Sissors/code/SLCD/#1579bcd31410
+https://mbed.org/users/Sissors/code/SLCD/#f70873bc6121
--- a/main.cpp	Mon Jan 20 21:08:57 2014 +0000
+++ b/main.cpp	Mon Jan 27 21:58:45 2014 +0000
@@ -1,18 +1,19 @@
 #include "mbed.h"
 #include "SLCD.h"
 
-time_t seconds = time(NULL); // needed to start rtc
+time_t seconds = time(NULL); // needed to start rtc on reset to maintain reasonable time if hard reset
 
 SLCD slcd;
 Timer scroll;
-
+DigitalOut  led1(LED1);
+DigitalOut  led2(LED2);
 InterruptIn setmin (SW1);
 InterruptIn sethour (SW3);
 
 struct tm t;
 
-int i,j,k,lastscroll,display,minute,hour,colon,dp;
-char message[80];
+int i,j,k,lastscroll,display_timer,minute,hour,colon,dp;
+char message[60];
 void scroll_message();
 char buffer[32];
 
@@ -21,82 +22,57 @@
 
 
 main()
-{   
+{
+    slcd.All_Segments(1);
+    wait(2);
+    slcd.All_Segments(0);
+    wait(1);    
+    
+    led1 = 1;led2 = 1;
+    
+    sprintf(message, "    rtc clock    s3 sets the hours    s1 sets the minutes");
     
-    slcd.LCD_All_Segments_ON();
-    wait(.5);
-    slcd.LCD_All_Segments_OFF ();
-    wait(.5);
-    slcd.printf("    ");
-    wait(.5);
-    slcd.COLON_ON();
-    wait(.5);
-    slcd.DP1_ON();
-    wait(.5);
-    slcd.DP2_ON();
-    wait(.5);
-    slcd.DP3_ON();
-    wait(.5);   
-    slcd.printf("8888");
-    wait(.5);
-    slcd.COLON_OFF();
-    wait(.5);
-    slcd.DP1_OFF();
-    wait(.5);
-    slcd.DP2_OFF();
-    wait(.5);
-    slcd.DP3_OFF();
-    wait(.5);
-    slcd.DP1_ON();
-    wait(.5);
-    slcd.DP2_ON();
-    wait(.5);
-    slcd.DP3_ON();
-    wait(.5); 
-    slcd.LCD_All_Segments_OFF();     
+// scrolling message    
+    scroll.start();
+    while (i<58) {
+
+        while (i<58) {
+            scroll_message();
+         }
+    }
+    wait(1);
+    
+    setmin.rise(setminIRQ);     // start set Minutes IRQ
+    sethour.rise(sethourIRQ);   // start set Hours IRQ
     
-    sprintf(message, "    1234567890    ABCDEFGHIJKLMNOPQRSTUVWXYZ");
-                
-    scroll.start();
-    while (i<44){
-        
-        while (i<44) {
-            scroll_message();                     
+// rtc clock function    
+    while(1) {
+
+        time_t seconds = time(NULL);
+
+        if(display_timer>6) {
+            strftime(buffer, 4, "%H%M", localtime(&seconds));// display Hours,Minutes for 2 seconds
+            slcd.Colon(1);led2=0;
+            slcd.DP2(0);led1=1;
+        } else {
+            strftime(buffer, 4, "%M%S", localtime(&seconds));// display Minutes,Seconds for 8 seconds            
+            slcd.Colon(0);led2=1;
+            slcd.DP2(1);led1=0;
         }
+        slcd.printf(buffer);
+        wait(.5);
+        slcd.DP2(0);led1=1;
+        display_timer++;
+        if (display_timer>9)display_timer=0;
+        wait(.5);
     }
-     
-    
-   setmin.rise(setminIRQ);
-   sethour.rise(sethourIRQ);
-     
-  while(1){
-    
-    time_t seconds = time(NULL); 
-        
-    if(display>14) {
-        strftime(buffer, 4, "%H%M", localtime(&seconds));colon=1;dp=0;;
-        }
-        else{strftime(buffer, 4, "%M%S", localtime(&seconds));dp=1;colon=0;}
-      
-    if(colon){slcd.COLON_ON();slcd.DP2_OFF();}
-    if(dp){slcd.DP2_ON();slcd.COLON_OFF();}
-    slcd.printf(buffer);
-    wait(.25);
-    if(colon)slcd.COLON_ON();
-    if(dp){slcd.DP2_OFF();slcd.COLON_OFF();}
-    slcd.printf(buffer);
-    display++;
-    if (display>19)display=0;
-     wait(.25); 
-       
- } 
-}   
+}
 
 void scroll_message()
 {
-    if (scroll.read_ms() > lastscroll + 200) {
+    if (scroll.read_ms() > lastscroll + 350) {
         scroll.reset();
-        if (i > 44) {
+        if (i > 58) {
             i=0;
         }
         int j, k = i;
@@ -113,46 +89,48 @@
     }
 }
 
-void setminIRQ(void)
+void setminIRQ(void) // set Minutes ISR
 {
-    display=15;
+    display_timer=7;
     time_t seconds = time(NULL);
-    char buffer[2]; 
+    char buffer[2];
     strftime(buffer, 2,"%H", localtime(&seconds));
-    hour = atoi(buffer);     
+    hour = atoi(buffer);    // get Hour integer
     strftime(buffer, 2,"%M", localtime(&seconds));
-    minute = atoi(buffer);
+    minute = atoi(buffer);  // get Minutes integer
     minute++;
-    if(minute>59) minute=0;     
-    t.tm_sec = 0; 
-    t.tm_min = minute;  
-    t.tm_hour = hour;   
-    t.tm_mday = 28;  
-    t.tm_mon = 1;     
-    t.tm_year = 114;  
+    if(minute>59) minute=0;
+    t.tm_sec = 0;   // Seconds reset to zero
+    t.tm_min = minute;
+    t.tm_hour = hour;
+    t.tm_mday = 1;
+    t.tm_mon = 2;
+    t.tm_year = 114;
     set_time (mktime(&t));
-    
+
 }
 
-void sethourIRQ(void)
+void sethourIRQ(void) // set Hours ISR
 {
-    display=15;
+    display_timer=7;
     time_t seconds = time(NULL);
     char buffer[2];
+    strftime(buffer, 2,"%H", localtime(&seconds));
+    hour = atoi(buffer);    // get Hour integer
     strftime(buffer, 2,"%M", localtime(&seconds));
-    minute = atoi(buffer);      
-    strftime(buffer, 2,"%H", localtime(&seconds));
-    hour = atoi(buffer);
+    minute = atoi(buffer);  // get Minutes integer
     hour++;
-    if(hour>23) hour=0;     
-    t.tm_sec = 0; 
-    t.tm_min = minute;  
-    t.tm_hour = hour;   
-    t.tm_mday = 28;  
-    t.tm_mon = 1;     
-    t.tm_year = 114;  
+    if(hour>23) hour=0;
+    t.tm_sec = 0;   // Seconds reset to zero
+    t.tm_min = minute;
+    t.tm_hour = hour;
+    t.tm_mday = 1;
+    t.tm_mon = 2;
+    t.tm_year = 114;
     set_time (mktime(&t));
-    
+
 }
 
 
+
+