Professional Documents
Culture Documents
RTC
RTC
DS 1307
,
DS1307
, real time Clock
DS1307 I2C ,
.
:
: 2200 32.768
: 2200
,
.
;)( deley
,
,
.
;)(: millis
DELAY
,
Overflow To zero 56 !
,
,
millis .
DS1307 ,
8BIT
.
"
, , .. "
0x01
0x06 .
, 8bit 4bit
" " Ones 4bit
Tens
.
, DS1307
" Binary coded
decimal"BCD ,
.
, ,
,
" "
Binary
. Decimal
:
(1
(2 . DS1307
(3 . CR 3v
(4
(5 32.768KHz
. BreadBoard (6
(7 . 2.2K
,
32.768KHz 3V
,
.
3V
,
.
:
:
(1 Wire.h
I2C
(2 RTClib.h
.
:
Wire.h
I2C
, DS1307
slave
.
,
DS1307
.
,
.
//This code taken from bilder blog http://bildr.org/2011/03/ds1307-arduino/
#include "Wire.h"
#define ADDRESS 0x68
byte Reset = 0x00; //workaround for issue #527
void setup(){
Wire.begin();
Serial.begin(9600);
setDateTime(); //This function where we Put Adjust the time and Date
}
void loop(){
printDate();//Print the Time and the Date on Serial Monitor
delay(1000);
}
void setDateTime(){
byte second =
00; //0-59
byte minute =
00; //0-59
byte hour =
17; //0-23
byte weekDay =
1; //1-7
2; //1-12
12; //0-99
Wire.beginTransmission(ADDRESS);
Wire.write(Reset); //stop Oscillator
Wire.write(DecToBcd(second));
Wire.write(DecToBcd(minute));
Wire.write(DecToBcd(hour));
Wire.write(DecToBcd(weekDay));
Wire.write(DecToBcd(monthDay));
Wire.write(DecToBcd(month));
Wire.write(DecToBcd(year));
Wire.write(Reset); //start
Wire.endTransmission();
void printDate(){
Wire.requestFrom(ADDRESS, 7);
DS1307
.
,
..
{)(void setDateTime
.
:
RTClib.h :
,
,
, RTClib
.
"
" ,
:
// Date and time functions using a DS1307 RTC connected via I2C and Wir
e lib
:
RTC.adjust(DateTime(__DATE__,
__TIME__)):
.
DS1307
,
.
now.unixtime():
Unix
1970\1\1
, .
, Serial Monitor
". " Seven segment,LCD,Etc