“SKU:RB-02S101 RTC时钟模块”的版本间的差异
来自ALSROBOT WiKi
(→产品相关推荐) |
(→使用方法) |
||
第83行: | 第83行: | ||
===程序效果=== | ===程序效果=== | ||
[[文件:RB02S10103.png|420px|缩略图|居中]] | [[文件:RB02S10103.png|420px|缩略图|居中]] | ||
+ | |||
+ | ==扩展例程== | ||
+ | |||
+ | * 硬件准备 | ||
+ | # Carduino UNO R3 控制器 * 1 个 | ||
+ | # V5.0 传感器扩展板 * 1 个 | ||
+ | # 四位七段数码管 * 1 个 | ||
+ | # RTC 时钟模块 * 1 个 | ||
+ | # 传感器连接线若干 | ||
+ | |||
+ | * 硬件连接 | ||
+ | [[文件: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> | ||
+ | |||
+ | * 程序效果 | ||
+ | 数码管实时电子时钟。 | ||
==产品相关推荐== | ==产品相关推荐== |
2016年7月30日 (六) 13:13的版本
目录 |
产品概述
产品是一款低功耗,具有56字节非失性RAM的全BCD码时钟日历实时时钟模块,芯片可以提供秒,分,小时等信息,每一个月的天数能自动调整。并且有闰年补偿功能。AM/PM 标志位决定时钟工作于24小时或12小时模式,芯片有一个内置的电源感应电路,具有掉电检测和电池切换功能。当单片机断电情况下,可以通过一个电池让单片机项目时间保持记录,完善的数据记录。
规格参数
- 产品货号:
- 工作电压 :+5v
- 主控芯片:DS1307
- 工作温度范围:0°C to +70°C
- 接口类型:IIC 通信接口
- 固定孔:4个 * M3
- 产品尺寸:45mm * 25mm
接口定义
RTC时钟模块引脚定义:
- SDA:I2C 数据引脚
- SCK:I2C 时钟引脚
- +:电源(VCC)
- -:地(GND)
使用方法
硬件连接
例子程序
将下列程序上传到 Carduino 控制器中
- 点击此处 Arduino 入门教程查看程序上传方法
- 例子程序下载
将下载到的压缩文件解压到到 Arduino IDE 软件的 libraries 文件中(·····\arduino-1.7.6\libraries),启动 Arduino IDE 选择文件 -- 示例 -- RB-02S101_RTC_Module-master -- 打开 example - ds1307 例子程序,上传到 Arduino UNO 控制器中,就可以实现代码测试。操作方法下图所示:
解压过程
// 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); }
程序效果
扩展例程
- 硬件准备
- Carduino UNO R3 控制器 * 1 个
- V5.0 传感器扩展板 * 1 个
- 四位七段数码管 * 1 个
- RTC 时钟模块 * 1 个
- 传感器连接线若干
- 硬件连接
- 例子程序
#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; }
- 程序效果
数码管实时电子时钟。
产品相关推荐
产品购买地址
RTC 时钟模块
周边产品推荐
串行1602液晶显示模块
1602液晶扩展板 v2.0 Arduino LCD 1602 Keypad Shield
Arduino四位七段数码管