Demo code for PCF2127 (and PCF2129) library. This code can be executed with LCD screen on AppBoard. PCF2127 and PCF2129 are high accuracy real-time-clock (RTC) module. This library provides simple interface to accessing clock information.
Dependencies: C12832 PCF2127 mbed
main.cpp
00001 /* 00002 * A sample code for PCF2127 library 00003 * 00004 * @author Akifumi (Tedd) OKANO, NXP Semiconductors 00005 * @version 1.5 00006 * @date 04-Dec-2014 00007 * 00008 * PCF2127 is a "real time clock (RTC)" module which is including a Xtal and TCXO 00009 * http://www.nxp.com/products/interface_and_connectivity/real_time_clocks/rtcs_with_temp_compensation/series/PCF2127.html 00010 * 00011 * RTC initializing part is ported from.. 00012 * http://mbed.org/users/roen/notebook/real-time/ 00013 * 00014 * This code is refined version of.. 00015 * http://developer.mbed.org/users/okano/code/NXP_PCF2127A/ 00016 */ 00017 00018 #include "mbed.h" 00019 #include "C12832.h" 00020 #include "PCF2127.h" 00021 00022 C12832 lcd( p5, p7, p6, p8, p11 ); 00023 PCF2127 rtc( p28, p27 ); 00024 00025 void show_time( void ); 00026 void set_time( void ); 00027 00028 int main() 00029 { 00030 printf( "PCF2127 demo started.\r\n" ); 00031 00032 if ( rtc.is_init_required() ) { 00033 lcd.locate( 0, 0 ); 00034 lcd.printf( "please set time on terminal" ); 00035 00036 set_time(); 00037 00038 lcd.cls(); 00039 } 00040 00041 lcd.locate( 0,20 ); 00042 lcd.printf( "PCF2127 demo" ); 00043 00044 while ( 1 ) { 00045 show_time(); 00046 wait( 0.1 ); 00047 } 00048 } 00049 00050 void show_time( void ) 00051 { 00052 struct tm dt, *dtp; 00053 time_t t; 00054 char s[ 30 ]; 00055 dtp = &dt; 00056 00057 rtc.clear_intr(); 00058 00059 // get time information from PCF2127 00060 t = rtc.time( NULL ); 00061 dtp = localtime( &t ); 00062 00063 // print time and date on terminal 00064 strftime( s, 30, "%H:%M:%S, %Y/%b/%d %a", dtp ); 00065 printf( "%s\r\n", s ); 00066 00067 // print time on LCD screen 00068 strftime( s, 20, "%H:%M:%S PCF2127", dtp ); 00069 lcd.locate( 0, 0 ); 00070 lcd.printf( "%s", s ); 00071 00072 // print date on LCD screen 00073 strftime( s, 20, "%Y/%b/%d(%a)", dtp ); 00074 lcd.locate( 0, 10 ); 00075 lcd.printf( "%s", s ); 00076 } 00077 00078 void set_time( void ) 00079 { 00080 #define MAX_CHAR_LENGTH 21 00081 char s[ MAX_CHAR_LENGTH ]; 00082 00083 printf( "Enter current date and time:\r\n" ); 00084 printf( "YYYY MM DD HH MM SS[enter]\r\n" ); 00085 00086 fgets( s, MAX_CHAR_LENGTH, stdin ); 00087 printf( "user input: \"%s\"\r\n", s ); 00088 00089 rtc.set_time( s ); 00090 } 00091
Generated on Tue Jul 19 2022 22:54:13 by
1.7.2
PCF2127 and PCF2129 High-accuracy RTC module