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

DS3234实时时钟驱动仿真

1、DS3234介绍

DS3234 是一款低成本、极其精确的 SPI 总线实时时钟 (RTC),具有集成的温度补偿晶体振荡器 (TCXO) 和晶体。 DS3234 集成了一个精密的温度补偿电压基准和比较器电路来监控

V

C

C

V_{CC}

VCC​。当

V

C

C

V_{CC}

VCC​ 降至低于电源故障电压 (

V

P

F

V_{PF}

VPF​) 时,器件会置位

R

S

T

\over RST

RST​ 输出,并在 VCC 降至

V

P

F

V_{PF}

VPF​和

V

B

A

T

V_{BAT}

VBAT​ 以下时禁用对器件的读写访问。

R

S

T

\over RST

RST​ 引脚作为按钮输入进行监控,以产µP 复位。当设备的主电源中断时,设备切换到备用电源输入并保持准确计时。晶体谐振器的集成提高了设备的长期精度,并减少了生产线上的零件数量。 DS3234 可在商业和工业温度范围内使用,并采用行业标准的 300 密耳、20 引脚 SO 封装。
DS3234 还集成了 256 字节的电池供电 SRAM。在主电源断电的情况下,存储器的内容由连接到 VBAT 引脚的电源维持。 RTC 维护秒、分、小时、日、日、月和年信息。月末的日期会自动调整少于 31 天的月份,包括闰年的更正。时钟以 24 小时或 12 小时格式运行,带有

A

M

\over AM

AM​/PM 指示器。提供了两个可编程的时间警报和一个可编程的方波输出。地址和数据通过 SPI 双向总线串行传输。

在这里插入图片描述

DS3234的引脚功能如下:

在这里插入图片描述

DS3234经典应用电路如下:

在这里插入图片描述

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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*
DS3234\_RTC\_Demo.ino
Jim Lindblom @ SparkFun Electronics
original creation date: October 2, 2016
https://github.com/sparkfun/SparkFun\_DS3234\_RTC\_Arduino\_Library

Configures, sets, and reads from the DS3234 real-time clock (RTC).

Resources:
SPI.h - Arduino SPI Library

Development environment specifics:
Arduino 1.6.8
SparkFun RedBoard
SparkFun Real Time Clock Module (v14)
\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/
#include <SPI.h>
#include <SparkFunDS3234RTC.h>

// Comment out the line below if you want date printed before month.
// E.g. October 31, 2016: 10/31/16 vs. 31/10/16
#define PRINT\_USA\_DATE

//
// Configurable Pin Definitions //
//
#define DS13074\_CS\_PIN 10 // DeadOn RTC Chip-select pin
//#define INTERRUPT\_PIN 2 // DeadOn RTC SQW/interrupt pin (optional)

void setup()
{
// Use the serial monitor to view time/date output
Serial.begin(9600);
#ifdef INTERRUPT\_PIN // If using the SQW pin as an interrupt
pinMode(INTERRUPT_PIN, INPUT_PULLUP);
#endif

// Call rtc.begin([cs]) to initialize the library
// The chip-select pin should be sent as the only parameter
rtc.begin(DS13074_CS_PIN);
//rtc.set12Hour(); // Use rtc.set12Hour to set to 12-hour mode

// Now set the time...
// You can use the autoTime() function to set the RTC's clock and
// date to the compiler's predefined time. (It'll be a few seconds
// behind, but close!)
rtc.autoTime();
// Or you can use the rtc.setTime(s, m, h, day, date, month, year)
// function to explicitly set the time:
// e.g. 7:32:16 | Monday October 31, 2016:
//rtc.setTime(16, 32, 7, 2, 31, 10, 16); // Uncomment to manually set time

// Update time/date values, so we can set alarms
rtc.update();
// Configure Alarm(s):
// (Optional: enable SQW pin as an interrupt)
rtc.enableAlarmInterrupt();
// Set alarm1 to alert when seconds hits 30
rtc.setAlarm1(30);
// Set alarm2 to alert when minute increments by 1
rtc.setAlarm2(rtc.minute() + 1);
}

void loop()
{
static int8\_t lastSecond = -1;

// Call rtc.update() to update all rtc.seconds(), rtc.minutes(),
// etc. return functions.
rtc.update();

// if (rtc.second() != lastSecond) // If the second has changed
// {
printTime(); // Print the new time

//lastSecond = rtc.second(); // Update lastSecond value
// }

// Check for alarm interrupts
#ifdef INTERRUPT\_PIN
// Interrupt pin is active-low, if it's low, an alarm is triggered
if (!digitalRead(INTERRUPT_PIN))
{
#endif
// Check rtc.alarm1() to see if alarm 1 triggered the interrupt
if (rtc.alarm1())
{
Serial.println("ALARM 1!");
// Re-set the alarm for when s=30:
rtc.setAlarm1(30);
}
// Check rtc.alarm2() to see if alarm 2 triggered the interrupt
if (rtc.alarm2())
{
Serial.println("ALARM 2!");
// Re-set the alarm for when m increments by 1
rtc.setAlarm2(rtc.minute() + 1, rtc.hour());
}
#ifdef INTERRUPT\_PIN
}
#endif
delay(1000);
}

void printTime()
{
Serial.print(String(rtc.hour()) + ":"); // Print hour
if (rtc.minute() < 10)
Serial.print('0'); // Print leading '0' for minute
Serial.print(String(rtc.minute()) + ":"); // Print minute
if (rtc.second() < 10)
Serial.print('0'); // Print leading '0' for second
Serial.print(String(rtc.second())); // Print second

if (rtc.is12Hour()) // If we're in 12-hour mode
{
// Use rtc.pm() to read the AM/PM state of the hour
if (rtc.pm()) Serial.print(" PM"); // Returns true if PM
else Serial.print(" AM");
}

Serial.print(" | ");

// Few options for printing the day, pick one:
Serial.print(rtc.dayStr()); // Print day string
//Serial.print(rtc.dayC()); // Print day character
//Serial.print(rtc.day()); // Print day integer (1-7, Sun-Sat)
Serial.print(" - ");
#ifdef PRINT\_USA\_DATE
Serial.print(String(rtc.month()) + "/" + // Print month
String(rtc.date()) + "/"); // Print date
#else
Serial.print(String(rtc.date()) + "/" + // (or) print date
String(rtc.month()) + "/"); // Print month
#endif
Serial.println(String(rtc.year())); // Print year
}

4、仿真结果

在这里插入图片描述

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