SKU:RB-02S101 RTC时钟模块

来自ALSROBOT WiKi
2018年1月18日 (四) 15:05Arduino77讨论 | 贡献的版本

跳转至: 导航搜索
RB02S1010111.png

目录

产品概述

RTC 时钟模块是一款低功耗,具有 56 字节非失性 RAM 的全 BCD 码时钟日历实时时钟模块,芯片可以提供秒,分,小时等信息,每一个月的天数能自动调整。并且有闰年补偿功能。AM/PM 标志位决定时钟工作于 24 小时或 12 小时模式,芯片有一个内置的电源感应电路,具有掉电检测和电池切换功能。当单片机断电情况下,可以通过一个电池让单片机项目时间保持记录,完善的数据记录。

规格参数

  1. 产品货号:RB-02S101
  2. 工作电压:DC 5V
  3. 主控芯片:DS1307
  4. 晶振频率:32.768 KHz
  5. 工作温度范围:0°C to +70°C
  6. 接口类型:IIC 通信接口
  7. 配套电池型号:3V CR1220 纽扣电池
  8. 固定孔:4个 * M3
  9. 产品尺寸:45mm * 25mm
  • 产品尺寸图:
Size032.jpg

接口定义

RTC时钟模块引脚定义:

  • SDA:I2C 数据引脚
  • SCK:I2C 时钟引脚
  • +:电源(VCC)
  • -:地(GND)

使用方法1(Arduino 控制器)

使用硬件

  • Arduino UNO 控制器
  • RTC 时钟模块
  • USB 数据线
  • 杜邦线若干

硬件连接

RB02S10102.png

Arduino_code_1

#include <Wire.h>
#include "RTClib.h"

RTC_DS1307 rtc;

char daysOfTheWeek[7][12] = {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};

void setup () {
  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(F(__DATE__), F(__TIME__))); //获取电脑的系统时间
   // rtc.adjust(DateTime(2017, 4, 2, 13, 57, 0));
  }
}

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

程序效果

RB02S10103.png

使用方法2(Arduino 控制器)

使用硬件

  • Arduino UNO R3 控制器 * 1 个
  • V5.0 传感器扩展板 * 1 个
  • 四位七段数码管 * 1 个
  • RTC 时钟模块 * 1 个
  • 传感器连接线若干

硬件连接

RB05L021100.png

Arduino_code_2

#include <TimerOne.h>
#include "TM1637.h"
#include <Wire.h>
#include "RTClib.h"
#define ON 1
#define OFF 0

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);
  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(F(__DATE__), F(__TIME__))); //获取电脑的系统时间
   // rtc.adjust(DateTime(2017, 4, 2, 13, 57, 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;
}

程序效果

数码管实时电子时钟。

产品相关推荐

Erweima.png

例子程序下载

例子程序及库文件下载链接:https://pan.baidu.com/s/1c3II3ao 密码:fyab

产品购买地址

RTC 时钟模块

周边产品推荐

串行1602液晶显示模块
1602液晶扩展板 v2.0 Arduino LCD 1602 Keypad Shield
Arduino四位七段数码管

相关学习资料

DS1307 datasheet