极客工坊

 找回密码
 注册

QQ登录

只需一步,快速开始

查看: 12229|回复: 3

DS1302走时不准?

[复制链接]
发表于 2015-6-2 00:58:51 | 显示全部楼层 |阅读模式
// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// A quick demo of how to use my DS1302-library to
// quickly send time and date information over a serial link
//
// I assume you know how to connect the DS1302.
// DS1302:  CE pin    -> Arduino Digital 2
//          I/O pin   -> Arduino Digital 3
//          SCLK pin  -> Arduino Digital 4

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(5, 6, 7);

void setup()
{
  // Set the clock to run-mode, and disable the write protection
  rtc.halt(false);
  rtc.writeProtect(false);
  
  // Setup Serial connection
  Serial.begin(9600);

  // The following lines can be commented out to use the values already stored in the DS1302
  rtc.setDOW(MONDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 1, 2015);   // Set the date to August 6th, 2010
}

void loop()
{
  // Send Day-of-Week
  Serial.print(rtc.getDOWStr());
  Serial.print(" ");
  
  // Send date
  Serial.print(rtc.getDateStr());
  Serial.print(" -- ");

  // Send time
  Serial.println(rtc.getTimeStr());
  
  // Wait one second before repeating
  delay (1000);
}
为什么走的时间跟设置的不一致啊???

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?注册

x
回复

使用道具 举报

发表于 2015-6-2 01:21:37 | 显示全部楼层
换个库试试. https://github.com/msparks/arduino-ds1302
回复 支持 反对

使用道具 举报

发表于 2015-6-2 10:48:32 | 显示全部楼层
DS1302模块与Arduino之间连线要短,试试看
回复 支持 反对

使用道具 举报

发表于 2015-6-2 11:44:24 | 显示全部楼层
这东西放1个星期能差1个小时出来。。。。很正常。买 3231会好很多。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|联系我们|极客工坊

GMT+8, 2026-6-16 15:13 , Processed in 0.058880 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表