关于ARDUINO使用DS1302高精度时钟模块的探索(01)

本文详细介绍了如何在ARDUINO上使用DS1302高精度时钟模块,包括硬件连接、程序解析及库文件的使用。重点讲解了设置时间和日期的步骤,以及自定义日期格式和时间显示的方法。在实践中发现年-月-日格式显示异常,通过修改库文件解决了问题,并提供了修改后的库文件链接。
摘要由CSDN通过智能技术生成

DS1302模块的使用

DS1302时钟模块的特性是在外部切断电源时可以启用内部电源(纽扣电池)供电,保证时间记录不会被消除,只需要设定写入一次正确时间,此后每次读取到的都是正确时间。

硬件连接

DS1302:

DS1302 Arduino uno R3
DAT 3
DAT 2
SCLK 7
                   **注意vcc------3.3v**

程序解释(以库自带实例程序为例)

位置如图DS1302库自带实例程序
代码如下

// 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 7

#include <DS1302.h>

// Init the DS1302
DS1302 rtc(2, 3, 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(FRIDAY);        // Set Day-of-Week to FRIDAY
  rtc.setTime(12, 0, 0);     // Set the time to 12:00:00 (24hr format)
  rtc.setDate(6, 8, 2013);   // Set the date to August 6th, 2010
}

void loop
  • 4
    点赞
  • 43
    收藏
    觉得还不错? 一键收藏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值