DS1302模块的使用
DS1302时钟模块的特性是在外部切断电源时可以启用内部电源(纽扣电池)供电,保证时间记录不会被消除,只需要设定写入一次正确时间,此后每次读取到的都是正确时间。
硬件连接
DS1302:
DS1302 | Arduino uno R3 |
---|---|
DAT | 3 |
DAT | 2 |
SCLK | 7 |
**注意vcc------3.3v**
程序解释(以库自带实例程序为例)
位置如图
代码如下
// 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