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

MCP79412实时时钟驱动仿真

1、MCP79412介绍

MCP79412 通用 I2C™ 兼容实时时钟 / 日历(RTCC)与非易失性存储器和通常在高价设备中常见的高级功能高度集成。 这些功能包括用于备用电源的电池切换电路、用于记录电源故障的时间戳和用于准确性的数字微调。 使用低成本的 32.768 kHz 晶体或其他时钟源,以 12 小时或 24 小时格式跟踪时间,并带有 AM/PM 指示器和计时到秒、分、小时、星期几、天、 月和年。 作为中断或唤醒信号,多功能开漏输出可被编程为报警输出或时钟输出,支持 4 个可选频率。 此外,非易失性存储器与唯一 ID 一起包含在 EEPROM 的锁定部分中,该部分在工厂使用 EUI-48 MAC 地址进行编程。

MCP79412有以下特性:

  • 小时、分钟、秒、星期几、日、月、年
  • 闰年补偿到 2399
  • 12/24 小时模式
  • 1 PPM 分辨率
  • ±129 PPM 范围
  • 双可编程报警
  • 具有可选频率的时钟输出
  • 报警输出
  • 通用输出
  • 切换到备用电池和从备用电池切换的时间记录
  • I2C 时钟频率高达 400 kHz
  • 64 字节电池供电 SRAM
  • 1Kb EEPROM 存储器
  • 健壮的写解锁序列
  • 预编程的 EUI-64™ MAC 地址
  • 工作电压 1.8V 至 5.5V
  • 备份电压 1.3V 至 5.5V
  • 低典型计时电流
  • 自动切换到备用电池
    在这里插入图片描述

典型的MCP79412应用电路如下:

在这里插入图片描述

MCP79412引脚功能如下:

在这里插入图片描述

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
#include <Wire.h>
#include <RTCx.h>

void setup(void)
{
Serial.begin(9600);
Serial.println("\*\*\*\*MCP7941X\*\*\*\*");
Wire.begin();
if (rtc.autoprobe()) {
// Found something, hopefully a clock.
Serial.print("Autoprobe found ");
Serial.print(rtc.getDeviceName());
Serial.print(" at 0x");
Serial.println(rtc.getAddress(), HEX);
}
// rtc.clearPowerFailFlag();
// Enable the battery backup. This happens by default on the DS1307
// but needs to be enabled on the MCP7941x.
rtc.enableBatteryBackup();
// 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/121262735