日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Arduino--DS3231实时时钟模块

發(fā)布時間:2024/10/14 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Arduino--DS3231实时时钟模块 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

(1)簡介

DS3231是一種實時的RCT IC芯片,通過IIC接口進(jìn)行通信,默認(rèn)IIC通信地址為(0X68,應(yīng)該是在頭文件中有體現(xiàn),大概看了下也沒找見),其內(nèi)部還集成了晶體振蕩器和溫度傳感器,無需連接外部晶體。

DS3231模塊如下圖所示,包含RTC芯片和一個32K的EEPROM
自身帶有3V CR2032鋰電池,掉電時間不變

包括年、月、日、時、分、秒等具體時間信息

(2)連線

主要是IIC接口,本實驗室是基于Arduino UNO使用,其他開發(fā)板的IIC管腳參考以下鏈接:
https://blog.csdn.net/u011816009/article/details/106566177

UNODS3231
5VVCC
GNDGND
A4SDA
A5SCL

(3)程序

DS3231的程序分為兩個部分,第一部分是設(shè)置起始日歷信息(年、月、日、時、分、秒),第二部分是具體顯示部分,分別闡述如下:

設(shè)置日歷

// DS3231_Serial_Easy // Copyright (C)2015 Rinky-Dink Electronics, Henning Karlsen. All right reserved // web: http://www.RinkyDinkElectronics.com/ // // A quick demo of how to use my DS3231-library to // quickly send time and date information over a serial link // // To use the hardware I2C (TWI) interface of the Arduino you must connect // the pins as follows: // // Arduino Uno/2009: // ---------------------- // DS3231: SDA pin -> Arduino Analog 4 or the dedicated SDA pin // SCL pin -> Arduino Analog 5 or the dedicated SCL pin // // Arduino Leonardo: // ---------------------- // DS3231: SDA pin -> Arduino Digital 2 or the dedicated SDA pin // SCL pin -> Arduino Digital 3 or the dedicated SCL pin // // Arduino Mega: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL pin // // Arduino Due: // ---------------------- // DS3231: SDA pin -> Arduino Digital 20 (SDA) or the dedicated SDA1 (Digital 70) pin // SCL pin -> Arduino Digital 21 (SCL) or the dedicated SCL1 (Digital 71) pin // // The internal pull-up resistors will be activated when using the // hardware I2C interfaces. // // You can connect the DS3231 to any available pin but if you use any // other than what is described above the library will fall back to // a software-based, TWI-like protocol which will require exclusive access // to the pins used, and you will also have to use appropriate, external // pull-up resistors on the data and clock signals. //#include <DS3231.h>// Init the DS3231 using the hardware interface DS3231 rtc(SDA, SCL);void setup() {// Setup Serial connectionSerial.begin(115200);// Uncomment the next line if you are using an Arduino Leonardo//while (!Serial) {}// Initialize the rtc objectrtc.begin();// The following lines can be uncommented to set the date and timertc.setDOW(FRIDAY); // Set Day-of-Week to SUNDAYrtc.setTime(14, 26, 50); // Set the time to 12:00:00 (24hr format)rtc.setDate(3, 8, 2019); // Set the date to January 1st, 2014 }void loop() {// Send Day-of-WeekSerial.print(rtc.getDOWStr());Serial.print(" ");// Send dateSerial.print(rtc.getDateStr());Serial.print(" -- ");// Send timeSerial.println(rtc.getTimeStr());// Wait one second before repeating :)delay (1000); }

時鐘顯示

#include <DS3231.h>// Init the DS3231 using the hardware interface DS3231 rtc(SDA, SCL);void setup() {// Setup Serial connectionSerial.begin(115200);// Uncomment the next line if you are using an Arduino Leonardo//while (!Serial) {}// Initialize the rtc objectrtc.begin();// The following lines can be uncommented to set the date and time//rtc.setDOW(WEDNESDAY); // Set Day-of-Week to SUNDAY//rtc.setTime(12, 0, 0); // Set the time to 12:00:00 (24hr format)//rtc.setDate(1, 1, 2014); // Set the date to January 1st, 2014 }void loop() {// Send Day-of-WeekSerial.print(rtc.getDOWStr());Serial.print(" ");// Send dateSerial.print(rtc.getDateStr());Serial.print(" -- ");// Send timeSerial.println(rtc.getTimeStr());// Wait one second before repeating :)delay (1000); }

總結(jié)

以上是生活随笔為你收集整理的Arduino--DS3231实时时钟模块的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。