DS1302 라이브러리는 여러개 있습니다.
이중 현재 아듀이노 스케치에서 기본으로 제공하는 라이브러리는 ds1302.h 입니다.
그러나 DS1302RTC.h 파일은 공식적으로 지원하지 않고 외부에서 구해서 zip 파일로 다운로드 한 후
아듀이노 스케치 라이브러리 메니저에서 zip 자체를 라이브러리로 설치할 수 있습니다. 압축을 풀지 않는 상태로...
DS1302RTC 라이브러리를 사용시에는 TimeLib.h 라이;브러리가 필요합니다. 같이 설치하시면 됩니다.
그러나 DS1302RTC 라이브러리는 사용치 마세요.
라이브러리 자체 버그가 있어 빌드에러 납니다.
또한 Arduino 스케치에서 제공하는 DS1302 라이브러리 또한 빌드에러가 납니다.
이 또한 사용치 마시고 다음 게시판에 올리는 RTC.LIB를 사용하세요
완벽히 동작합니다.
12시간제나 24시간제는 내가 프로그램하기 나름입니다.
Data Sheet 와 라이브러를 파일을 첨부하오니 참고삼아 보시고 돌려 보세요
샘플소스코드 또한 첨부합니다.. 기냥 보세요
/// DS1302 라이브러리 사용예제
// DS1302_Serial_Easy
// Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved
// web: http://www.RinkyDinkElectronics.com/
//
// 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(2, 3, 4);
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(11, 47, 5); // Set the time to 12:00:00 (24hr format)
rtc.setDate(15, 8, 2016); // 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);
}
//===============================
// DS1302RTC 라이브러 사용예제
// DS1302_Serial_Easy (C)2010 Henning Karlsen
// web: http://www.henningkarlsen.com/electronics
//
// Adopted for DS1302RTC library by Timur Maksimov 2014
//
// 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 27
// I/O pin -> Arduino Digital 29
// SCLK pin -> Arduino Digital 31
// VCC pin -> Arduino Digital 33
// GND pin -> Arduino Digital 35
#include <Time.h>
#include <DS1302RTC.h>
// Set pins: CE, IO,CLK
DS1302RTC RTC(2, 3, 4); // 수정한 부분
// Optional connection for RTC module
#define DS1302_GND_PIN 33
#define DS1302_VCC_PIN 35
void setup() {
// Setup Serial connection
Serial.begin(9600);
Serial.println("DS1302RTC Read Test");
Serial.println("-------------------");
// Activate RTC module
digitalWrite(DS1302_GND_PIN, LOW);
pinMode(DS1302_GND_PIN, OUTPUT);
digitalWrite(DS1302_VCC_PIN, HIGH);
pinMode(DS1302_VCC_PIN, OUTPUT);
Serial.println("RTC module activated");
Serial.println();
delay(500);
if (RTC.haltRTC()) {
Serial.println("The DS1302 is stopped. Please run the SetTime");
Serial.println("example to initialize the time and begin running.");
Serial.println();
}
if (!RTC.writeEN()) {
Serial.println("The DS1302 is write protected. This normal.");
Serial.println();
}
delay(5000);
}
void loop() {
tmElements_t tm;
Serial.print("UNIX Time: ");
Serial.print(RTC.get());
if (! RTC.read(tm)) {
Serial.print(" Time = ");
print2digits(tm.Hour);
Serial.write(':');
print2digits(tm.Minute);
Serial.write(':');
print2digits(tm.Second);
Serial.print(", Date (D/M/Y) = ");
Serial.print(tm.Day);
Serial.write('/');
Serial.print(tm.Month);
Serial.write('/');
Serial.print(tmYearToCalendar(tm.Year));
Serial.print(", DoW = ");
Serial.print(tm.Wday);
Serial.println();
} else {
Serial.println("DS1302 read error! Please check the circuitry.");
Serial.println();
delay(9000);
}
// Wait one second before repeating :)
delay (1000);
}
void print2digits(int number) {
if (number >= 0 && number < 10)
Serial.write('0');
Serial.print(number);
}