FRMD KL25Z <=i2c=> NXP PCF8563 (RTC) FRMD KL25Z SPI=> MCP23S17 => (GLCD) T6963C FRMD KL25Z Tsi => 3 button : <--> <enter> <++> FRMD KL25Z => Bip()

Dependencies:   TSI mbed

Fork of RTC8564NB_Clock by masa miya

Revision:
1:7c1d3790f08d
Parent:
0:50e7bcac5eb9
Child:
2:c271f83a69e4
--- a/main.cpp	Tue Apr 26 07:53:06 2011 +0000
+++ b/main.cpp	Wed Apr 27 11:03:21 2011 +0000
@@ -1,6 +1,11 @@
-/*This is the clock which used highly quality RTC module RT8564NB. 
+/*
+This is the clock which used highly quality RTC module RT8564NB. 
 This module is I2C controllable. At the time of poweron/reset, the start 
-time received from ntp server. 
+time received from ntp server.
+
+Revision History:
+Rev. 0.01A 2011/04/26 New
+Rev. 0.01B 2011/04/27 Add time justify function, sec LED 
  */
 #include "mbed.h"
 #include "TextLCD.h"
@@ -31,6 +36,10 @@
 EthernetNetIf eth; 
 NTPClient ntp;
 I2C i2c(p9, p10);
+DigitalOut sec_led(LED1);
+DigitalOut test_led(LED2);
+InterruptIn just_button(p15);
+
 int offset_JAPAN = 32400;
 
 char year, month, day, week;
@@ -63,8 +72,29 @@
     
     return value;
 }
+
+void time_just()
+{
+    char _min, _hour;
+    test_led = !test_led;
+    _min = rtc_read(MINUTES);
+    if (_min >= 0x30) { 
+            _hour = rtc_read(HOURS);
+            if (_hour == 0x23)
+                _hour = 0x00;
+            else if ((_hour & 0x0F) == 0x09)
+                _hour = (_hour & 0xF0) + 0x10;
+            else
+                _hour = _hour + 0x01;
+            rtc_write(HOURS, _hour);
+    }
+    rtc_write(MINUTES, 0x00);
+    rtc_write(SECONDS, 0x00);
+}
     
 int main() {
+    just_button.rise(&time_just);
+
     lcd.cls();
     lcd.printf("RTC8564NB CLOCK" );
     wait(2.0);
@@ -145,6 +175,8 @@
             ((hour >> 4) & 0x03) + 0x30, (hour & 0x0F) + 0x30, 
                 (minute >> 4) + 0x30, (minute & 0x0F) + 0x30, 
                     (sec >> 4) + 0x30, (sec & 0x0F) + 0x30 );
-        wait(1.0);
+        
+        sec_led = !sec_led;
+        wait(0.5);
     }
 }