資源簡介
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í)間???名稱
-----------?---------??----------?-----??----
?????目錄???????????0??2016-03-03?22:43??DS3231\
?????文件???????16274??2016-03-03?22:43??DS3231\DS3231.cpp
?????文件????????5160??2016-03-03?22:43??DS3231\DS3231.h
?????目錄???????????0??2016-03-03?22:43??DS3231\Examples\
?????目錄???????????0??2016-03-03?22:43??DS3231\Examples\DS3231_TEST\
?????文件????????4647??2016-03-03?22:43??DS3231\Examples\DS3231_TEST\DS3231_TEST.ino
?????文件?????????548??2016-03-03?22:43??DS3231\keywords.txt
?????文件?????????243??2016-03-03?22:43??DS3231\Readme.txt
- 上一篇:DELPHI數(shù)據(jù)庫編程
- 下一篇:LDPC的VHDL程序
評(píng)論
共有 條評(píng)論