附一段有问题的代码,想要将DS1302的时分秒分别拿出来但是失败了 void print_time() { /* 从 DS1302 获取当前时间 */ Time t = rtc.time(); /* 将星期从数字转换为名称 */ memset(day, 0, sizeof(day)); switch (t.day) { case 1: strcpy(day, "Sunday"); break; case 2: strcpy(day, "Monday"); break; case 3: strcpy(day, "Tuesday"); break; case 4: strcpy(day, "Wednesday"); break; case 5: strcpy(day, "Thursday"); break; case 6: strcpy(day, "Friday"); break; case 7: strcpy(day, "Saturday"); break; } /* 将日期代码格式化凑成buf等待输出 */ char* i=buf; Serial.println(i); snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d", day, t.yr, t.mon, t.date, t.hr, t.min, t.sec); /* 输出日期到串口 */ Serial.println(buf); int hour=t.hr; int minute=t.min; int second=t.sec; }
|