查看SKU:RB-02S101 RTC時鐘模塊的源代碼
←
SKU:RB-02S101 RTC時鐘模塊
跳轉至:
導航
、
搜索
因為以下原因,你沒有權限編輯本頁:
您剛才請求的操作只有這個用戶組中的用戶才能使用:
用戶
您可以查看并復制此頁面的源代碼:
[[文件:RB02S101011.png|500px|縮略圖|右]] ==產(chǎn)品概述== 產(chǎn)品是一款低功耗,具有56字節(jié)非失性RAM的全BCD碼時鐘日歷實時時鐘模塊,芯片可以提供秒,分,小時等信息,每一個月的天數(shù)能自動調整。并且有閏年補償功能。AM/PM 標志位決定時鐘工作于24小時或12小時模式,芯片有一個內置的電源感應電路,具有掉電檢測和電池切換功能。當單片機斷電情況下,可以通過一個電池讓單片機項目時間保持記錄,完善的數(shù)據(jù)記錄。 ==規(guī)格參數(shù)== # 產(chǎn)品貨號: # 工作電壓 :+5v # 主控芯片:DS1307 # 工作溫度范圍:0°C to +70°C # 接口類型:IIC 通信接口 # 固定孔:4個 * M3 # 產(chǎn)品尺寸:45mm * 25mm ==接口定義== RTC時鐘模塊引腳定義: * SDA:I2C 數(shù)據(jù)引腳 * SCK:I2C 時鐘引腳 * +:電源(VCC) * -:地(GND) ==使用方法== ===硬件連接=== [[文件:RB02S10102.png|700px|縮略圖|居中]] ===例子程序=== 將下列程序上傳到 Carduino 控制器中 * [http://gharee.com/wiki/index.php/Arduino%E5%85%A5%E9%97%A8%E6%95%99%E7%A8%8B#Arduino.E7.82.B9.E4.BA.AELED.E5.AE.9E.E9.AA.8C 點擊此處 Arduino 入門教程]查看程序上傳方法 * [https://github.com/chenboyang77/RB-02S101_RTC_Module.git 例子程序下載] 將下載到的壓縮文件解壓到到 Arduino IDE 軟件的 libraries 文件中(·····\arduino-1.7.6\libraries),啟動 Arduino IDE 選擇文件 -- 示例 -- RB-02S101_RTC_Module-master -- 打開 example - ds1307 例子程序,上傳到 Arduino UNO 控制器中,就可以實現(xiàn)代碼測試。操作方法下圖所示:<br/> 解壓過程<br/> [[文件:05L007A10.png|500px|縮略圖|居中]] [[文件:05L007A11.png|700px|縮略圖|居中]] <pre style='color:blue'> // Date and time functions using a DS1307 RTC connected via I2C and Wire lib #include <Wire.h> #include "RTClib.h" #if defined(ARDUINO_ARCH_SAMD) // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero! #define Serial SerialUSB #endif RTC_DS1307 rtc; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; void setup () { #ifndef ESP8266 while (!Serial); // for Leonardo/Micro/Zero #endif Serial.begin(57600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); // following line sets the RTC to the date & time this sketch was compiled //rtc.adjust(DateTime(F(__DATE__), F(__TIME__))); // This line sets the RTC with an explicit date & time, for example to set rtc.adjust(DateTime(2016, 7, 27, 13, 0, 0));//2016年7月27,13點整 } } void loop () { DateTime now = rtc.now(); Serial.print(now.year(), DEC); Serial.print('/'); Serial.print(now.month(), DEC); Serial.print('/'); Serial.print(now.day(), DEC); Serial.print(" ("); Serial.print(daysOfTheWeek[now.dayOfTheWeek()]); Serial.print(") "); Serial.print(now.hour(), DEC); Serial.print(':'); Serial.print(now.minute(), DEC); Serial.print(':'); Serial.print(now.second(), DEC); Serial.println(); delay(3000); }</pre> ===程序效果=== [[文件:RB02S10103.png|420px|縮略圖|居中]] ==擴展例程== * 硬件準備 # Carduino UNO R3 控制器 * 1 個 # V5.0 傳感器擴展板 * 1 個 # 四位七段數(shù)碼管 * 1 個 # RTC 時鐘模塊 * 1 個 # 傳感器連接線若干 * 硬件連接 [[文件:RB05L021100.png|600px|縮略圖|居中]] * 例子程序 可通過選擇示例 - ClockDisplay_now 打開例程,也可以通過復制程序粘貼到 IDE 的編輯界面 <br/> <pre style='color:blue'>#include <TimerOne.h> #include "TM1637.h" #include <Wire.h> #include "RTClib.h" #define ON 1 #define OFF 0 #if defined(ARDUINO_ARCH_SAMD) #define Serial SerialUSB #endif RTC_DS1307 rtc; char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; int8_t TimeDisp[] = {0x00,0x00,0x00,0x00}; unsigned char ClockPoint = 1; unsigned char Update; unsigned char minute = 0; unsigned char hour = 12; int stem,val; #define CLK 5 #define DIO 4 TM1637 tm1637(CLK,DIO); void setup() { tm1637.set(); tm1637.init(); Timer1.initialize(500000); Timer1.attachInterrupt(TimingISR); #ifndef ESP8266 while (!Serial); #endif Serial.begin(57600); if (! rtc.begin()) { Serial.println("Couldn't find RTC"); while (1); } if (! rtc.isrunning()) { Serial.println("RTC is NOT running!"); rtc.adjust(DateTime(2016, 7, 27, 13, 0, 0)); } } void loop() { DateTime now = rtc.now(); if(Update == ON) { TimeUpdate(); tm1637.display(TimeDisp); } stem = now.hour(); val = now.minute(); } void TimingISR() { ClockPoint = (~ClockPoint) & 0x01; Update = ON; } void TimeUpdate(void) { if(ClockPoint)tm1637.point(POINT_ON); else tm1637.point(POINT_OFF); TimeDisp[0] = stem/ 10; TimeDisp[1] = stem % 10; TimeDisp[2] = val / 10; TimeDisp[3] = val % 10; }</pre> * 程序效果 數(shù)碼管實時電子時鐘。 ==產(chǎn)品相關推薦== [[文件:erweima.png|230px|無框|右]] ===產(chǎn)品購買地址=== RTC 時鐘模塊<br/> ===周邊產(chǎn)品推薦=== [http://gharee.com/goods-130.html 串行1602液晶顯示模塊]<br/> [http://gharee.com/goods-45.html 1602液晶擴展板 v2.0 Arduino LCD 1602 Keypad Shield]<br/> [http://gharee.com/goods-743.html Arduino四位七段數(shù)碼管]<br/> ===相關學習資料=== [http://datasheets.maximintegrated.com/en/ds/DS1307.pdf DS1307 datasheet]
返回
SKU:RB-02S101 RTC時鐘模塊
。
來自“
http://gharee.com/wiki/index.php/SKU:RB-02S101_RTC時鐘模塊
”
導航菜單
個人工具
登錄
名字空間
頁面
討論
變換
查看
閱讀
查看源代碼
查看歷史
操作
搜索
導航
首頁
社區(qū)專頁
新聞動態(tài)
最近更改
隨機頁面
工具箱
鏈入頁面
相關更改
特殊頁面
頁面信息
隱私政策
關于ALSROBOT WiKi
免責聲明