资源简介
arduino DS3231库 时钟模块
代码片段和文件信息
/*
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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 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数据库编程
- 下一篇:LDPC的VHDL程序
相关资源
- Arduino串口转发源代码
- arduino+rc522读写卡
- arduino_code.rar
- arduino和ds1302的基于lcd12864闹钟,按键
- Arduino-TMC2130Stepper.zip
- Arduino-smartcar_shield.zip
- 基于arduino的温度检测和显示
- TFmini_Plus I²C版在Arduino上的例程及参考
- pid算法-arduino
- HidEmuKbd.bin
- arduino编程库函数合集
- arduino JSON数据格式库
- proteus arduino仿真库
- arduino 多个程序一起工作程序
- arduino蜂鸣器和光控灯实验报告
- Arduino自动浇花系统_一路继电器控制水
- Arduino小车控制程序含遥控+寻迹+避障
- TM1637显示器arduino库文件
- arduino rfid库函数
- 基于arduino的循迹小车不含有PID算法
- 基于arduino的循迹小车含有PID算法
- 基于arduino的无线温湿度传输系统
- Arduino多任务同时进行.rar
- arduino 机械臂 画圆程序 通过Arduino控制
- PS2+ arduino+接线图+源码
- CH340G-CH340通用驱动 支持win10/win7 64位驱
- 智能小车黑线循迹&超声波避障综合实
- arduino光电编码器程序
- Arduino智能鱼缸
- arduino pid循迹代码.zip
评论
共有 条评论