資源簡介
Arduino DS3231函數(shù)庫

代碼片段和文件信息
/*
DS3231.cpp:?DS3231?Real-Time?Clock?library
original?code?by
Eric?Ayars
4/1/11
updated?to?Arduino?1.0?
John?Hubert
Feb?7?2012
Released?into?the?public?domain.
*/
#include?
#define?CLOCK_ADDRESS?0x68
//?Constructor
DS3231::DS3231()?{
//?nothing?to?do?for?this?constructor.
}
/*****************************************?
Public?Functions
?*****************************************/
void?DS3231::getTime(byte&?year?byte&?month?byte&?date?byte&?DoW?byte&?hour?byte&?minute?byte&?second)?{
byte?tempBuffer;
bool?PM;
bool?h12;
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x00));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?7);
second?=?bcdToDec(Wire.read());
minute?=?bcdToDec(Wire.read());
tempBuffer?=?bcdToDec(Wire.read());
h12?=?tempBuffer?&?0b01000000;
if?(h12)?{
PM?=?tempBuffer?&?0b00100000;
hour?=?bcdToDec(tempBuffer?&?0b00011111);
}?else?{
hour?=?bcdToDec(tempBuffer?&?0b00111111);
}
DoW?=?bcdToDec(Wire.read());
date?=?bcdToDec(Wire.read());
month?=?bcdToDec(Wire.read()?&?0b01111111);
year?=?bcdToDec(Wire.read());
}
byte?DS3231::getSecond()?{
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x00));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
return?bcdToDec(Wire.read());
}
byte?DS3231::getMinute()?{
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(0x01);
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
return?bcdToDec(Wire.read());
}
byte?DS3231::getHour(bool&?h12?bool&?PM)?{
byte?temp_buffer;
byte?hour;
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(0x02);
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
temp_buffer?=?Wire.read();
h12?=?temp_buffer?&?0b01000000;
if?(h12)?{
PM?=?temp_buffer?&?0b00100000;
hour?=?bcdToDec(temp_buffer?&?0b00011111);
}?else?{
hour?=?bcdToDec(temp_buffer?&?0b00111111);
}
return?hour;
}
byte?DS3231::getDoW()?{
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x03));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
return?bcdToDec(Wire.read());
}
byte?DS3231::getDate()?{
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x04));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
return?bcdToDec(Wire.read());
}
byte?DS3231::getMonth(bool&?Century)?{
byte?temp_buffer;
byte?hour;
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x05));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
temp_buffer?=?Wire.read();
Century?=?temp_buffer?&?0b10000000;
return?(bcdToDec(temp_buffer?&?0b01111111))?;
}
byte?DS3231::getYear()?{
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.write(uint8_t(0x06));
Wire.endTransmission();
Wire.requestFrom(CLOCK_ADDRESS?1);
return?bcdToDec(Wire.read());
}
void?DS3231::setSecond(byte?Second)?{
//?Sets?the?seconds?
//?This?function?also?resets?the?Oscillator?Stop?Flag?which?is?set
//?whenever?power?is?interrupted.
Wire.beginTransmission(CLOCK_ADDRESS);
Wire.wr
?屬性????????????大小?????日期????時(shí)間???名稱
-----------?---------??----------?-----??----
?????文件??????16274??2012-02-08?22:56??DS3231\DS3231.cpp
?????文件???????5136??2016-11-29?15:28??DS3231\DS3231.h
?????文件???????5160??2015-12-30?16:27??DS3231\DS3231.h.bak
?????文件???????4647??2013-05-31?15:41??DS3231\Examples\DS3231_TEST\DS3231_TEST.ino
?????文件????????548??2012-02-07?11:17??DS3231\keywords.txt
?????文件????????243??2012-02-08?23:05??DS3231\Readme.txt
?????目錄??????????0??2015-12-14?17:13??DS3231\Examples\DS3231_TEST
?????目錄??????????0??2015-12-14?17:13??DS3231\Examples
?????目錄??????????0??2016-11-29?15:28??DS3231
-----------?---------??----------?-----??----
????????????????32008????????????????????9
評(píng)論
共有 條評(píng)論