中级
30 分钟

使用M41T82和PIC18F24K50制作您自己的时间导航器

超越滴答声:RTC正在改变未来

RTC 9 Click with EasyPIC v8

已发布 6月 26, 2024

点击板

RTC 9 Click

开发板

EasyPIC v8

编译器

NECTO Studio

微控制器单元

PIC18F24K50

为您的解决方案解锁精确的计时控制和同步功能,采用高性能实时时钟解决方案。

A

A

硬件概览

它是如何工作的?

RTC 9 Click 基于 STMicroelectronics 的 M41T82,这是一款极低功耗的实时时钟/日历 (RTC) 模块。由于其高度集成,这个模块提供了高时间精度,出厂校准至±5 ppm,即使经过两次回流焊接后,外部组件的数量也非常少。它具有完整的RTC功能,提供可编程计数器、报警和带有可选择事件报告源的中断引擎。操作参数存储在内部用户SRAM存储器中,该存储器由电池供电,因此在完全断电的情况下也能保持其持久性。M41T82 具有内置的32.768 kHz振荡器。

然而,为了达到最佳精度,RTC 9 Click 也配备了一个外部振荡器。寄存器映射中的八个字节用于时钟/日历功能,并以二进制编码十进制 (BCD) 格式配置。额外的17个字节的寄存器映射提供了两个报警的状态/控制、看门狗、8位计数器和方波功能。另有七个字节作为用户SRAM可用。M41T82 支持 I2C 通信接口,这也用于 RTC 9 Click 通过 mikroBUS 插座与主微控制器通信。用户可用的功能包括非易失性、时间钟/日历、两个报警中断、看门狗定时器、可编程8

位计数器和方波输出。八个时钟地址位置包含世纪、年、月、日、星期、小时、分钟、秒以及百分之一秒/千分之一秒,均以24小时BCD格式显示。对28天、29天(闰年)、30天和31天的月份自动进行修正。该 Click board™ 可以在3.3V或5V逻辑电压水平下工作,可通过VCC SEL跳线选择。这样,3.3V和5V的MCU都可以正确使用通信线路。此外,该 Click board™ 配备了一个包含易于使用的功能和示例代码的库,可以用于进一步开发。

RTC 9 Click top side image
RTC 9 Click bottom side image

功能概述

开发板

EasyPIC v8 是一款专为快速开发嵌入式应用的需求而特别设计的开发板。它支持许多高引脚计数的8位PIC微控制器,来自Microchip,无论它们的引脚数量如何,并且具有一系列独特功能,例如首次集成的调试器/程序员。开发板布局合理,设计周到,使得最终用户可以在一个地方找到所有必要的元素,如开关、按钮、指示灯、连接器等。得益于创新的制造技术,EasyPIC v8 提供了流畅而沉浸式的工作体验,允许在任何情况下、任何地方、任何时候都能访问。

EasyPIC v8 开发板的每个部分都包含了使同一板块运行最高效的必要组件。除了先进的集成CODEGRIP程 序/调试模块,该模块提供许多有价值的编程/调试选项和与Mikroe软件环境的无缝集成外,该板还包括一个干净且调节过的开发板电源供应模块。它可以使用广泛的外部电源,包括电池、外部12V电源供应和通过USB Type-C(USB-C)连接器的电源。通信选项如USB-UART、USB DEVICE和CAN也包括在内,包括 广受好评的mikroBUS™标准、两种显示选项(图形和

基于字符的LCD)和几种不同的DIP插座。这些插座覆盖了从最小的只有八个至四十个引脚的8位PIC MCU的广泛范围。EasyPIC v8 是Mikroe快速开发生态系统的一个组成部分。它由Mikroe软件工具原生支持,得益于大量不同的Click板™(超过一千块板),其数量每天都在增长,它涵盖了原型制作和开发的许多方面。

EasyPIC v8 horizontal image

微控制器概述 

MCU卡片 / MCU

default

建筑

PIC

MCU 内存 (KB)

16

硅供应商

Microchip

引脚数

28

RAM (字节)

2048

使用的MCU引脚

mikroBUS™映射器

NC
NC
AN
Reset
RA0
RST
NC
NC
CS
NC
NC
SCK
NC
NC
MISO
NC
NC
MOSI
Power Supply
3.3V
3.3V
Ground
GND
GND
NC
NC
PWM
NC
NC
INT
NC
NC
TX
NC
NC
RX
I2C Clock
RC3
SCL
I2C Data
RC4
SDA
Power Supply
5V
5V
Ground
GND
GND
2

“仔细看看!”

Click board™ 原理图

RTC 9 Click Schematic schematic

一步一步来

项目组装

EasyPIC v8 front image hardware assembly

从选择您的开发板和Click板™开始。以EasyPIC v8作为您的开发板开始。

EasyPIC v8 front image hardware assembly
GNSS2 Click front image hardware assembly
MCU DIP 40 hardware assembly
EasyPIC v8 Access DIPMB 1 - upright/background hardware assembly
Necto image step 2 hardware assembly
Necto image step 3 hardware assembly
Necto image step 4 hardware assembly
NECTO Compiler Selection Step Image hardware assembly
NECTO Output Selection Step Image hardware assembly
Necto image step 6 hardware assembly
Necto DIP image step 7 hardware assembly
Necto image step 8 hardware assembly
Necto image step 9 hardware assembly
Necto image step 10 hardware assembly
Necto PreFlash Image hardware assembly

实时跟踪您的结果

应用程序输出

此款Click板可通过两种方式进行接口连接和监控:

  • Application Output - 在调试模式下,使用“Application Output”窗口进行实时数据监控。按照本教程正确设置它。

软件支持

库描述

该库包含 RTC 9 Click 驱动程序的 API。

关键功能:

  • rtc9_set_time - 设置新时间 - 24小时格式

  • rtc9_get_time - 获取新时间 - 24小时格式

  • rtc9_get_date - 获取新日期

开源

代码示例

完整的应用程序代码和一个现成的项目可以通过NECTO Studio包管理器直接安装到NECTO Studio 应用程序代码也可以在MIKROE的GitHub账户中找到。

/*!
 * \file 
 * \brief Rtc9 Click example
 * 
 * # Description
 * This example demonstrates the use of RTC 9 click board.
 *
 * The demo application is composed of two sections :
 * 
 * ## Application Init 
 * Initializes the driver, wakes up the module, and sets the time and date.
 * 
 * ## Application Task  
 * Reads the current time and date and displays the results on the USB UART each second.
 * 
 * \author MikroE Team
 *
 */
// ------------------------------------------------------------------- INCLUDES

#include "board.h"
#include "log.h"
#include "rtc9.h"

// ------------------------------------------------------------------ VARIABLES

static rtc9_t rtc9;
static log_t logger;
static uint8_t seconds_old = 0;

// ------------------------------------------------------ APPLICATION FUNCTIONS

void application_init ( void )
{
    log_cfg_t log_cfg;
    rtc9_cfg_t cfg;
    rtc9_set_data_t set_data;

    /** 
     * Logger initialization.
     * Default baud rate: 115200
     * Default log level: LOG_LEVEL_DEBUG
     * @note If USB_UART_RX and USB_UART_TX 
     * are defined as HAL_PIN_NC, you will 
     * need to define them manually for log to work. 
     * See @b LOG_MAP_USB_UART macro definition for detailed explanation.
     */
    LOG_MAP_USB_UART( log_cfg );
    log_init( &logger, &log_cfg );
    log_info( &logger, "---- Application Init ----" );

    //  Click initialization.

    rtc9_cfg_setup( &cfg );
    RTC9_MAP_MIKROBUS( cfg, MIKROBUS_1 );
    rtc9_init( &rtc9, &cfg );

    Delay_ms( 500 );

    rtc9_wakeup( &rtc9 );

    rtc9_set_time( &rtc9, 23, 59, 50 );

    set_data.day = 22;
    set_data.day_of_week = RTC9_DAY_MONDAY;
    set_data.month = RTC9_MONTH_MARCH;
    set_data.year = 21;
    rtc9_set_date ( &rtc9, &set_data );
    
    rtc9_wakeup( &rtc9 );
}

void application_task ( void )
{
    rtc9_get_time_t get_time;
    rtc9_get_date_t get_date;

    char *week_string;
    char *month_string;

    rtc9_get_time( &rtc9, &get_time );
    rtc9_get_date( &rtc9, &get_date );
    
    if ( get_time.sec != seconds_old )
    {
        seconds_old = get_time.sec;
        log_printf( &logger, "- Time [ %.2u:%.2u:%.2u ] \r\n", ( uint16_t ) get_time.hour, 
                                                               ( uint16_t ) get_time.min, 
                                                               ( uint16_t ) get_time.sec );

        week_string = rtc9_current_day_of_week( get_date.day_of_week );
        month_string = rtc9_current_month( get_date.month );

        log_printf( &logger, "- Date [ %s, %s %.2u, %u ] \r\n", week_string, month_string, 
                                                               ( uint16_t ) get_date.day, 
                                                               ( uint16_t ) get_date.year + 2000 );
        log_printf( &logger, "---------------------------------------- \r\n" );
    }
    Delay_ms( 10 );
}

void main ( void )
{
    application_init( );

    for ( ; ; )
    {
        application_task( );
    }
}

// ------------------------------------------------------------------------ END

额外支持

资源

喜欢这个项目吗?

'购买此套件' 按钮会直接带您进入购物车,您可以在购物车中轻松添加或移除产品。