Demo code for PCF2127 (and PCF2129) library. Setting of time and displaying can be done on PC-terminal application through the USB Serial Port. PCF2127 and PCF2129 are high accuracy real-time-clock (RTC) module. This library provides simple interface to accessing clock information.
Demo code for PCF2127 library
Information
The "PCF2127" library works for PCF2127T, PCF2127AT, PCF2129T and PCF2129AT.
The device information is available on the component page and the library page.

PCF2127T is in SO16 package
Revision 0:658f351580f0, committed 2014-12-09
- Comitter:
- nxp_ip
- Date:
- Tue Dec 09 07:23:50 2014 +0000
- Child:
- 1:86dc8dfe6a20
- Commit message:
- A sample code for PCF2127 library. Initial version
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/PCF2127.lib Tue Dec 09 07:23:50 2014 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/nxp_ip/code/PCF2127/#700e0285cfd8
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Dec 09 07:23:50 2014 +0000
@@ -0,0 +1,77 @@
+/*
+ * A sample code for PCF2127 library
+ *
+ * @author Akifumi (Tedd) OKANO, NXP Semiconductors
+ * @version 1.6
+ * @date 09-Dec-2014
+ *
+ * PCF2127 is a "real time clock (RTC)" module which is including a Xtal and TCXO
+ * http://www.nxp.com/products/interface_and_connectivity/real_time_clocks/rtcs_with_temp_compensation/series/PCF2127.html
+ *
+ * RTC initializing part is ported from..
+ * http://mbed.org/users/roen/notebook/real-time/
+ *
+ * This code is refined version of..
+ * http://developer.mbed.org/users/okano/code/NXP_PCF2127A/
+ */
+ */
+
+#include "mbed.h"
+#include "PCF2127.h"
+
+PCF2127 rtc( p28, p27 );
+
+void show_time( void );
+void set_time( void );
+
+int main()
+{
+ printf( "PCF2127 demo started.\r\n" );
+
+ if ( rtc.is_init_required() ) {
+ set_time();
+ }
+
+ while ( 1 ) {
+ show_time();
+ wait( 0.25 );
+ }
+}
+
+void show_time( void )
+{
+ struct tm dt, *dtp;
+ time_t t;
+ char s[ 30 ];
+
+ dtp = &dt;
+
+ rtc.clear_intr();
+
+ // get time information from PCF2127
+ if ( PCF2127::TIME_FUNC_ERROR == (t = rtc.time( NULL )) )
+ {
+ printf( "error at reading time\r\n" );
+ return;
+ }
+
+ dtp = localtime( &t );
+
+ // print time and date on terminal
+ strftime( s, 30, "%H:%M:%S, %Y/%b/%d %a", dtp );
+ printf( "%s\r\n", s );
+}
+
+void set_time( void )
+{
+#define MAX_CHAR_LENGTH 21
+ char s[ MAX_CHAR_LENGTH ];
+
+ printf( "Enter current date and time:\r\n" );
+ printf( "YYYY MM DD HH MM SS[enter]\r\n" );
+
+ fgets( s, MAX_CHAR_LENGTH, stdin );
+ printf( "user input: \"%s\"\r\n", s );
+
+ rtc.set_time( s );
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Dec 09 07:23:50 2014 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/4fc01daae5a5 \ No newline at end of file
PCF2127 and PCF2129 High-accuracy RTC module