Arduino与Proteus仿真实例-DS1338低功耗实时时钟驱动仿真

DS1338低功耗实时时钟驱动仿真

1、DS1338介绍

DS1338 串行实时时钟 (RTC) 是一种低功耗、全二进制编码的十进制 (BCD) 时钟/日历加上 56 字节的 NV SRAM。 地址和数据通过 I2C 接口串行传输。 时钟/日历提供秒、分、小时、日、日期、月和年信息。 对于少于 31 天的月份,月末日期会自动调整,包括闰年的更正。 时钟以 24 小时或 12 小时格式运行,带有 AM/PM 指示器。 DS1338内置powersense电路,检测电源故障并自动切换到备用电源,保持时间和日期操作。

DS1338相当于DS1307升级版并且DS1338与DS1307驱动是兼容的。在前面的文章中对DS1307做了介绍,请参考:

在这里插入图片描述

典型的DS1338应用电路如下:

在这里插入图片描述

2、仿真电路原理图

在这里插入图片描述

3、仿真代码实现

本次实例使用的开源库如下:

演示代码如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include <Wire.h>
#include <RTCx.h>

void setup(void)
{
Serial.begin(9600);
Serial.println("\*\*\*\*DS1338\*\*\*\*");
rtc.setAddress(0x68);
Wire.begin();

// rtc.clearPowerFailFlag();

// Ensure the oscillator is running.
rtc.startClock();

if (rtc.getDevice() == RTCx::MCP7941x) {
Serial.print("Calibration: ");
Serial.println(rtc.getCalibration(), DEC);
// rtc.setCalibration(-127);
}

rtc.setSQW(RTCx::freq4096Hz);
}


const uint8\_t bufLen = 30;
char buffer[bufLen + 1] = {'\0'};
uint8\_t bufPos = 0;
unsigned long last = 0;
void loop(void)
{
struct RTCx::tm tm;
if (millis() - last >= 1000) {
last = millis();
rtc.readClock(tm);

RTCx::printIsotime(Serial, tm).println();
RTCx::time\_t t = RTCx::mktime(&tm);

Serial.print("unixtime = ");
Serial.println(t);
Serial.println("-----");
}
}

4、仿真结果

在这里插入图片描述

文章来源: https://iotsmart.blog.csdn.net/article/details/121262688