ocrobot:modules:pcf8563
PCF8563实时时钟(RTC)模块
OCROBOT pcf8563是一款设计非常优秀的时间源模块,提供直接可以读取的年月日时间分钟秒,并且可以提供32.768khz 1024hz 1Hz的时钟信号,采用高精度的爱普生晶体,极其优秀的极低功耗。
参数数据
宽电压范围 1.0~5.5V
复位电压标准值Vlow=0.9V
超低功耗:典型值为 0.25uA (VDD=3.0V,Tamb=25℃)
可编程时钟输出频率为:32.768KHz 、1024Hz 、32Hz 、1Hz
四种报警功能和定时器功能。
产品图片
支持库(arduino)
示例代码
用串口给模块配置时间
/* Demonstration of Rtc_Pcf8563 Set Time. * 时钟时间初始化代码,初始化后时钟会一直运行,以后基本不需要重新初始化了。 *电路链接 * VCC to 5V * GND to GND * SCL to A5 * SDA to A4 */ #include <Wire.h> #include <Rtc_Pcf8563.h> //init the real time clock Rtc_Pcf8563 rtc; char data[15]; //(多一位作为结束符存储) char Str_year[3], Str_month[3], Str_date[3], Str_DoW[3], Str_hour[3], Str_minute[3], Str_second[3]; //字符串时间(多一位作为结束符存储空间) byte year, month, day, DoW, hour, minute, second; void setup() { Serial.begin(9600); //clear out the registers //set a time to start with. //day, weekday, month, century(1=1900, 0=2000), year(0-99) Serial.println("Please enter the time: year[2]month[2]date[2]DoW[2]hour[2]minute[2]second[2]"); Serial.println("example: 2014-12-3 Wednesday 14:15:15 enter:14120303141515"); } void loop() { if (Serial.available() >=14) //串口读取数据 { for (int a = 0; a <14; a++) { data[a] = Serial.read(); } Str_year[0] = data[0]; //拆包 Str_year[1] = data[1]; Str_month[0] = data[2]; Str_month[1] = data[3]; Str_date[0] = data[4]; Str_date[1] = data[5]; Str_DoW[0] = data[6]; Str_DoW[1] = data[7]; Str_hour[0] = data[8]; Str_hour[1] = data[9]; Str_minute[0] = data[10]; Str_minute[1] = data[11]; Str_second[0] = data[12]; Str_second[1] = data[13]; //Str to byte year = atoi(Str_year); //转换数据类型 month = atoi(Str_month); day = atoi(Str_date); DoW = atoi(Str_DoW); hour = atoi(Str_hour); minute = atoi(Str_minute); second = atoi(Str_second); // conf times; //写入时钟 rtc.initClock(); //day, weekday, month, century(1=1900, 0=2000), year(0-99) rtc.setDate(day, DoW, month, 0, year); //hr, min, sec rtc.setTime(hour, minute, second); } //both format functions call the internal getTime() so that the //formatted strings are at the current time/date. Serial.print(rtc.formatTime()); Serial.print("\r\n"); Serial.print(rtc.formatDate()); Serial.print("\r\n"); delay(1000); }
ocrobot/modules/pcf8563.txt · 最后更改: 2023/06/07 04:23 由 127.0.0.1