资源简介
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
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
文件 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
- 上一篇:mybatis demo mybatis
- 下一篇:IEEE14节点模型
相关资源
- arduino控制180度舵机和360度舵机
- Arduino程序设计-智能水杯源码及报告
- Proteus仿真Arduino控制OLED1306
- 基于arduino mega2560的步进电机控制
- arduino的i2c库 完整版
- Arduino从入门到精通全课时教程分享
- 两个Arduino库-Blynk-BlynkESP8266.zip
- arduino实验の互动式儿童玩具
- Arduino STM32 平衡小车之家平衡小车源码
- Timo_ws2812_control.zip
- 基于arduino的光电鼠标A3050数据读取
- ArduinoJson
- arduino通过485读取温度传感器驱动淘晶
- Arduino实现可手动绘制路线的智能小车
- ArduinoJson-5.13.5.rar
- Proteus仿真:arduino通过SPI驱动lcd1602(
- 基于arduino的手势控制器,通过手势控
- arduino uno 引脚图
- arduino多种器件库
- Arduino HMC5883L库文件
- arduino_LiquidCrystal_I2C库及proteus仿真LC
- Arduino_IRremote_master.zip
- Arduino中文手册
- Arduino Mini 资料
- 基于Arduino与LabVIEW的数据采集系统.v
- Arduino通过Ethernet扩展板实现网络远程
- 基于Arduino的-亚博 BST-BATCAR 智能小车底
- Arduino的PID库
- 基于labview和arduinod的超声波测距
- Arduino UNO R3开发板原理图
评论
共有 条评论