Arduino与Proteus仿真实例-DS1340实时时钟驱动仿真

DS1340实时时钟驱动仿真

DS1340 是一款实时时钟 (RTC)/日历,引脚兼容且功能等同于 STM41T00,包括软件时钟校准。 该器件还在 VBACKUP 引脚上提供涓流充电能力、较低的计时电压和振荡器停止标志。 寄存器映射的块访问与 ST 设备相同。 涓流充电器和标志需要两个单独访问的附加寄存器。 时钟/日历提供秒、分、小时、日、日、月和年信息。 内置功率检测电路检测电源故障并自动切换到备用电源。 在时钟继续运行时禁止读取和写入。该器件通过 I2C 双向总线串行编程。

在这里插入图片描述

在前面的文章中,对DS1340做了详细的介绍,请参考:

1、仿真电路原理图

在这里插入图片描述

2、仿真代码实现

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

演示的代码如下:

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
// Get date and time using a DS1340 RTC connected via I2C
//
// Connect SCL to Analog 0
// Connect SDA to Analog 1

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

RTC_DS1340 RTC;

void setup () {
Serial.begin(9600); // Set serial port speed
Wire.begin(); // Start the I2C
RTC.begin(); // Init RTC
RTC.adjust(DateTime(\_\_DATE\_\_, \_\_TIME\_\_));
Serial.println("\*\*\*\*DS1340\*\*\*\*");
}

void loop () {
DateTime now = RTC.now(); // Read the time and date from the DS1340

Serial.print(now.year(), DEC);
Serial.print('/');
Serial.print(now.month(), DEC);
Serial.print('/');
Serial.print(now.day(), DEC);
Serial.print(' ');
Serial.print(now.hour(), DEC);
Serial.print(':');
Serial.print(now.minute(), DEC);
Serial.print(':');
Serial.print(now.second(), DEC);
Serial.println();

delay(1000);
}

3、仿真结果

在这里插入图片描述

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