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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Arduino UNO DS3231高精度RTC芯片 制作时钟

發布時間:2024/1/1 编程问答 42 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Arduino UNO DS3231高精度RTC芯片 制作时钟 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.


DS3231 模塊

是一個時鐘模塊,上面包含一個紐扣電池位置,可以在主機斷電的情況下還可以繼續計算時間,以便以后記錄使用。


模塊參數:
?  1.尺寸:38mm(長)*22mm(寬)*14mm(高)
?  2.重量:8g
?  3.工作電壓:3.3--5.5V
?  4.時鐘芯片:高精度時鐘芯片DS3231
?  5.時鐘精度:0-40℃范圍內,精度2ppm,年誤差約1分鐘
?  6.帶2個日歷鬧鐘
?  7.可編程方波輸出
?  8.實時時鐘產生秒、分、時、星期、日期、月和年計時,并提供有效期到2100年的閏年補償
?  9.芯片內部自帶溫度傳感器,精度為±3℃
?  10.存儲芯片:AT24C32(存儲容量32K)
?  11.IIC總線接口,最高傳輸速度400KHz(工作電壓為5V時)
?  12.可級聯其它IIC設備,24C32地址可通過短路A0/A1/A2修改,默認地址為0x57
?  13.帶可充電電池LIR2032,保證系統斷電后,時鐘任然正常走動


實驗效果

通過設定時間的程序后,

我們運行顯示時間的程序,就可以看到時鐘模塊當前的時間了



BOM表

Arduino UNO??? *1

DS3231 時鐘模塊 *1

跳線若干



接線


Arduino ? Uno ? ? ? ? ? ? ? ? ? ? ? ? ? ? ? DS3231

? ? GND ? ? ? ? ? ? ? ? ? ? <---> ? ? ? ? ? ? ? ?GND

? ?5V ? ? ? ? ? ? ? ? ? ? ? ? ?<--->? ? ? ? ? ? ? ? VCC

? ?A4(SDA) ? ? ? ? ? ? ? ? ? ? ? ? ?<--->? ? ? ? ? ? ? ? SDA

? ?A5 (SCL) ? ? ? ? ? ? ? ? ? ? ? ??<--->? ? ? ? ? ? ? ? ?SCL


程序

需要下載庫

http://www.rinkydinkelectronics.com/library.php?id=74



設置時間的程序

// 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(WEDNESDAY); // Set Day-of-Week to SUNDAYrtc.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); }

顯示時間的程序

// 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 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); }


思路講解

1,#include <DS3231.h> ? ?//加載DS3231庫


2,DS3231 ?rtc(SDA, SCL); ? ?//設置I2C


3,rtc.begin(); ? //建立RTC對象


4,

? rtc.setDOW(WEDNESDAY); ? ? // 設置星期幾,例如 SUNDAY
? rtc.setTime(12, 0, 0); ? ? // 設置時間 12:00:00 (24小時制)
? rtc.setDate(1, 1, 2014); ? // 設置日期 ?1月,1日 ,2014 年

如果在顯示程序中,或不需要設置時間的時候,可以在前面加//給注釋掉


5,

rtc.getDOWStr() ? 獲取星期幾

rtc.getDateStr() ? ?獲取日期

rtc.getTimeStr() ? 獲取時間

總結

以上是生活随笔為你收集整理的Arduino UNO DS3231高精度RTC芯片 制作时钟的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。