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

PCF2123实时时钟驱动仿真

1、PCF2123介绍

PCF2123 是一款针对低功耗应用而优化的 CMOS 实时时钟 (RTC) 和日历。 数据通过串行外设接口(SPI 总线)串行传输,最大数据速率为 6.25 Mbit/s。 还提供闹钟和定时器功能,可以在中断引脚上生成唤醒信号。 偏移寄存器允许对时钟进行微调。PCF2123可以应用于计时应用电池供电设备、测光、高持续时间计时器、每日闹钟、低待机功耗应用等。

PCF2123有如下特点:

  • 实时时钟提供基于 32.768 kHz 石英晶体的年、月、日、工作日、小时、分钟和秒
  • 运行时的低备用电流:在 VDD = 2.0 V 和 Tamb = 25 ℃ 时典型值为 100 nA
  • 分辨率:秒到年
  • 看门狗功能
  • 具有中断功能的可自由编程的定时器和闹钟
  • 时钟工作电压:1.1 V 至 5.5 V
  • 具有独立但可组合的数据输入和输出的 3 线 SPI 总线
  • VDD = 1.8 V 至 5.5 V 时的串行接口
  • 1秒或1分钟中断输出
  • CL = 7 pF 的集成振荡器负载电容器
  • 内部上电复位 (POR)
  • 开漏中断和时钟输出引脚
  • 用于频率调整的可编程偏移寄存器

在这里插入图片描述

PCF2123的引脚功能如下:

在这里插入图片描述

2、仿真电路原理图

在这里插入图片描述

3、仿真代码实现

本次使用到如下开源库:

注意,需要将Time库的TimeLib.h更名为Time.h,否则pcf2123库会编译不通过

简单的演示代码如下:

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
/\*
Demonstrates how to set and get time from the RTC.

The type tmElements\_t and functions like breakTime() are from
the Time library.
\*/

#include <PCF2123.h>

PCF2123 rtc(9); /\* Chip enable on pin 9 \*/

void setup() {
tmElements\_t tm;
Serial.begin(57600);

Serial.println("Resetting RTC");
rtc.reset();

// Serial.println("Setting time to Tue, 08 Nov 2016 23:49:50");

/\* Convert Unix timestamp to tmElements\_t \*/
breakTime(1635732785, tm);
rtc.time\_set(&tm);
}

/\* Print human readable time \*/
void print\_time(tmElements\_t t) {
Serial.print(String("DateTime:") + (1970 + t.Year));
Serial.print(String("-") + t.Month);
Serial.print(String("-") + t.Day);
//Serial.print(String(" Wday ") + t.Wday);
Serial.print(String(" ") + t.Hour);
Serial.print(String(":") + t.Minute);
Serial.print(String(":") + t.Second);
Serial.println();
}

void loop() {
tmElements\_t t;

/\* Get and print current time \*/
rtc.time\_get(&t);
print\_time(t);

/\* Print Unix timestamp \*/
Serial.println("Unix time: ");
Serial.println(makeTime(t));

delay(1000);
}


4、仿真结果

在这里插入图片描述

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