“SKU:RB-02S101 RTC時(shí)鐘模塊”的版本間的差異
來(lái)自ALSROBOT WiKi
(→?產(chǎn)品相關(guān)推薦) |
(→?使用方法) |
||
第83行: | 第83行: | ||
===程序效果=== | ===程序效果=== | ||
[[文件:RB02S10103.png|420px|縮略圖|居中]] | [[文件:RB02S10103.png|420px|縮略圖|居中]] | ||
+ | |||
+ | ==擴(kuò)展例程== | ||
+ | |||
+ | * 硬件準(zhǔn)備 | ||
+ | # Carduino UNO R3 控制器 * 1 個(gè) | ||
+ | # V5.0 傳感器擴(kuò)展板 * 1 個(gè) | ||
+ | # 四位七段數(shù)碼管 * 1 個(gè) | ||
+ | # RTC 時(shí)鐘模塊 * 1 個(gè) | ||
+ | # 傳感器連接線(xiàn)若干 | ||
+ | |||
+ | * 硬件連接 | ||
+ | [[文件:RB05L021100.png|600px|縮略圖|居中]] | ||
+ | |||
+ | * 例子程序 | ||
+ | <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ù)碼管實(shí)時(shí)電子時(shí)鐘。 | ||
==產(chǎn)品相關(guān)推薦== | ==產(chǎn)品相關(guān)推薦== |
2016年7月30日 (六) 13:13的版本
目錄 |
產(chǎn)品概述
產(chǎn)品是一款低功耗,具有56字節(jié)非失性RAM的全BCD碼時(shí)鐘日歷實(shí)時(shí)時(shí)鐘模塊,芯片可以提供秒,分,小時(shí)等信息,每一個(gè)月的天數(shù)能自動(dòng)調(diào)整。并且有閏年補(bǔ)償功能。AM/PM 標(biāo)志位決定時(shí)鐘工作于24小時(shí)或12小時(shí)模式,芯片有一個(gè)內(nèi)置的電源感應(yīng)電路,具有掉電檢測(cè)和電池切換功能。當(dāng)單片機(jī)斷電情況下,可以通過(guò)一個(gè)電池讓單片機(jī)項(xiàng)目時(shí)間保持記錄,完善的數(shù)據(jù)記錄。
規(guī)格參數(shù)
- 產(chǎn)品貨號(hào):
- 工作電壓 :+5v
- 主控芯片:DS1307
- 工作溫度范圍:0°C to +70°C
- 接口類(lèi)型:IIC 通信接口
- 固定孔:4個(gè) * M3
- 產(chǎn)品尺寸:45mm * 25mm
接口定義
RTC時(shí)鐘模塊引腳定義:
- SDA:I2C 數(shù)據(jù)引腳
- SCK:I2C 時(shí)鐘引腳
- +:電源(VCC)
- -:地(GND)
使用方法
硬件連接
例子程序
將下列程序上傳到 Carduino 控制器中
- 點(diǎn)擊此處 Arduino 入門(mén)教程查看程序上傳方法
- 例子程序下載
將下載到的壓縮文件解壓到到 Arduino IDE 軟件的 libraries 文件中(·····\arduino-1.7.6\libraries),啟動(dòng) Arduino IDE 選擇文件 -- 示例 -- RB-02S101_RTC_Module-master -- 打開(kāi) example - ds1307 例子程序,上傳到 Arduino UNO 控制器中,就可以實(shí)現(xiàn)代碼測(cè)試。操作方法下圖所示:
解壓過(guò)程
// 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點(diǎn)整 } } 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); }
程序效果
擴(kuò)展例程
- 硬件準(zhǔn)備
- Carduino UNO R3 控制器 * 1 個(gè)
- V5.0 傳感器擴(kuò)展板 * 1 個(gè)
- 四位七段數(shù)碼管 * 1 個(gè)
- RTC 時(shí)鐘模塊 * 1 個(gè)
- 傳感器連接線(xiàn)若干
- 硬件連接
- 例子程序
#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; }
- 程序效果
數(shù)碼管實(shí)時(shí)電子時(shí)鐘。
產(chǎn)品相關(guān)推薦
產(chǎn)品購(gòu)買(mǎi)地址
RTC 時(shí)鐘模塊
周邊產(chǎn)品推薦
串行1602液晶顯示模塊
1602液晶擴(kuò)展板 v2.0 Arduino LCD 1602 Keypad Shield
Arduino四位七段數(shù)碼管