![Whadda DS1302 Скачать руководство пользователя страница 6](http://html1.mh-extra.com/html/whadda/ds1302/ds1302_user-manual_967100006.webp)
6
Whadda WPI301 DS1302 Real-time clock module example
This demo sets the time on the DS1302 RTC module to the compiled time of the sketch.
After this is configured the time returned by the DS1302 module is periodically printed on
the serial monitor
Check whadda.com for more information including a wiring diagram for this demo.
// CONNECTIONS:
// DS1302 CLK/SCLK --> 7
// DS1302 DAT/IO --> 6
// DS1302 RST/CE --> 5
// DS1302 VCC --> 3.3v - 5v
// DS1302 GND --> GND
*/
#include <ThreeWire.h>
#include <RtcDS1302.h>
ThreeWire myWire(6,7,5); // IO, SCLK, CE
RtcDS1302<ThreeWire> Rtc(myWire);
void setup ()
{
Serial.begin(57600);
Serial.print("compiled: ");
Serial.print(__DATE__);
Serial.println(__TIME__);
Rtc.Begin();
RtcDateTime compiled = RtcDateTime(__DATE__, __TIME__);
printDateTime(compiled);
Serial.println();
//Rtc.SetDateTime(compiled);
if (!Rtc.IsDateTimeValid())
{
// Common Causes:
// 1) first time you ran and the device wasn't running yet
// 2) the battery on the device is low or even missing
Serial.println("RTC lost confidence in the DateTime!");
Rtc.SetDateTime(compiled);
}
if (Rtc.GetIsWriteProtected())
{
Serial.println("RTC was write protected, enabling writing now");