资源简介
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程序
相关资源
- ADNS-3080光流传感器测试程序Arduino
- EESkill NRF24L01 无线模块用户手册
- Arduino nano 工程文件
- Arduino教程 Lesson 之--自制风扇
- 基于Arduino的智能环境监控系统设计
- 基于Arduino和Machtalk的温棚环境监测系
- arduino pca9685多舵机同时控制案例
- arduino技术内幕
- Arduino电子设计实战指南.零基础篇_超
- 物联网智能家居平台DIY:ARDUINO 物联网
- 实验1.zip arduino跑马灯led灯实验,串口
- opencat所有资料.zip
- arduino主机,stm8从机。I2C测试 。每次
- DS18B20_Serial_println.ino
- ps2手柄arduino库文件
- 基于手机蓝牙的arduino遥控小车
- arduino中的can库函数
- 密码+指纹锁资料包.rar
- 贝壳物联arduino esp8266 demo版本
- HMC5883L罗盘指南针模块库文件及中英文
- arduino 小贱钟源码及教程
- Atom-TMC2208Pilot在Arduino上运行的应用程
- 写字机制作方案
- PID-增量式PID和位置式PID算法实现和
- Building Wireless Sensor Networks Using Arduin
- vc控制Arduino,实现串口通信
- Arduino入门经典
- Arduino所有库.zip
- 基于STM32和arduino的MPU9250九轴传感器代
- GY-9960模块Keil 和Arduino驱动程序
评论
共有 条评论