- #include <stdio.h>
- #include <string.h>
- #include <DS1302.h>
- uint8_t CE_PIN = 5;
- uint8_t IO_PIN = 6;
- uint8_t SCLK_PIN = 7;
- char buf[31];
- int numdata[3] ={0}, j = 0, mark = 0;
- /* 创建 DS1302 对象 */
- DS1302 rtc(CE_PIN, IO_PIN, SCLK_PIN);
- void print_time()
- {
- /* 从 DS1302 获取当前时间 */
- Time t = rtc.time();
- snprintf(buf, sizeof(buf), "%02d:%02d:%02d", t.hr, t.min, t.sec);
- Serial.println(buf);
- }
- void setup()
- {
- Serial.begin(9600);
- rtc.write_protect(false);
- rtc.halt(false);
- }
- void loop()
- {
- print_time();
- delay(1000);
- }
复制代码
给你修改了 |