为什么用arduino对ds1302编程提取不到时间?

代码是这个:#include<stdio.h>#include<DS1302.h>namespace{//SettheappropriatedigitalI/Opinco... 代码是这个:
#include <stdio.h>
#include <DS1302.h>

namespace {

// Set the appropriate digital I/O pin connections. These are the pin
// assignments for the Arduino as well for as the DS1302 chip. See the DS1302
// datasheet:
//
// http://datasheets.maximintegrated.com/en/ds/DS1302.pdf
const int kCePin = 5; // Chip Enable
const int kIoPin = 6; // Input/Output
const int kSclkPin = 7; // Serial Clock

// Create a DS1302 object.
DS1302 rtc(kCePin, kIoPin, kSclkPin);

String dayAsString(const Time::Day day) {
switch (day) {
case Time::kSunday: return "Sunday";
case Time::kMonday: return "Monday";
case Time::kTuesday: return "Tuesday";
case Time::kWednesday: return "Wednesday";
case Time::kThursday: return "Thursday";
case Time::kFriday: return "Friday";
case Time::kSaturday: return "Saturday";
}
return "(unknown day)";
}

void printTime() {
// Get the current time and date from the chip.
Time t = rtc.time();

// Name the day of the week.
const String day = dayAsString(t.day);

// Format the time and date and insert into the temporary buffer.
char buf[50];
snprintf(buf, sizeof(buf), "%s %04d-%02d-%02d %02d:%02d:%02d",
day.c_str(),
t.yr, t.mon, t.date,
t.hr, t.min, t.sec);

// Print the formatted string to serial so we can see the time.
Serial.println(buf);
}

} // namespace

void setup() {
Serial.begin(9600);

// Initialize a new chip by turning off write protection and clearing the
// clock halt flag. These methods needn't always be called. See the DS1302
// datasheet for details.
rtc.writeProtect(false);
rtc.halt(false);

// Make a new time object to set the date and time.
// Sunday, September 22, 2013 at 01:38:50.
Time t(2013, 9, 22, 1, 38, 50, Time::kSunday);

// Set the time and date on the chip.
rtc.time(t);
}

// Loop and print the time every second.
void loop() {
printTime();
delay(1000);
}
串口监视器显示的却是(unknown day) 2000-00-00 00:00:00,连线是对的。
展开
 我来答
qq429433607
2019-09-14 · TA获得超过295个赞
知道小有建树答主
回答量:520
采纳率:58%
帮助的人:68.2万
展开全部
时序问题,或者是ds1302有问题,你可以描述详细点
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 1条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式