1.背景 第一次使用小华的MCU L136,官方例程里面的rtc_int例程,因为我的开发板两个晶振都没有连接所以改用内部晶振
2.代码
/******************************************************************************
* Copyright (C) 2017, Huada Semiconductor Co.,Ltd All rights reserved.
*
* This software is owned and published by:
* Huada Semiconductor Co.,Ltd ("HDSC").
*
* BY DOWNLOADING, INSTALLING OR USING THIS SOFTWARE, YOU AGREE TO BE BOUND
* BY ALL THE TERMS AND CONDITIONS OF THIS AGREEMENT.
*
* This software contains source code for use with HDSC
* components. This software is licensed by HDSC to be adapted only
* for use in systems utilizing HDSC components. HDSC shall not be
* responsible for misuse or illegal use of this software for devices not
* supported herein. HDSC is providing this software "AS IS" and will
* not be responsible for issues arising from incorrect user implementation
* of the software.
*
* Disclaimer:
* HDSC MAKES NO WARRANTY, EXPRESS OR IMPLIED, ARISING BY LAW OR OTHERWISE,
* REGARDING THE SOFTWARE (INCLUDING ANY ACOOMPANYING WRITTEN MATERIALS),
* ITS PERFORMANCE OR SUITABILITY FOR YOUR INTENDED USE, INCLUDING,
* WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, THE IMPLIED
* WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE OR USE, AND THE IMPLIED
* WARRANTY OF NONINFRINGEMENT.
* HDSC SHALL HAVE NO LIABILITY (WHETHER IN CONTRACT, WARRANTY, TORT,
* NEGLIGENCE OR OTHERWISE) FOR ANY DAMAGES WHATSOEVER (INCLUDING, WITHOUT
* LIMITATION, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION,
* LOSS OF BUSINESS INFORMATION, OR OTHER PECUNIARY LOSS) ARISING FROM USE OR
* INABILITY TO USE THE SOFTWARE, INCLUDING, WITHOUT LIMITATION, ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL OR CONSEQUENTIAL DAMAGES OR LOSS OF DATA,
* SAVINGS OR PROFITS,
* EVEN IF Disclaimer HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
* YOU ASSUME ALL RESPONSIBILITIES FOR SELECTION OF THE SOFTWARE TO ACHIEVE YOUR
* INTENDED RESULTS, AND FOR THE INSTALLATION OF, USE OF, AND RESULTS OBTAINED
* FROM, THE SOFTWARE.
*
* This software may be replicated in part or whole for the licensed use,
* with the restriction that this Disclaimer and Copyright notice must be
* included with each copy of this software, whether used in part or whole,
* at all times.
*/
/******************************************************************************/
/** \file main.c
**
** A detailed description is available at
** @link Sample Group Some description @endlink
**
** - 2016-02-16 1.0 XYZ First version for Device Driver Library of Module.
**
******************************************************************************/
/******************************************************************************
* Include files
******************************************************************************/
#include "rtc.h"
#include "lpm.h"
#include "gpio.h"
/******************************************************************************
* Local pre-processor symbols/macros ('#define')
******************************************************************************/
/******************************************************************************
* Global variable definitions (declared in header file with 'extern')
******************************************************************************/
/******************************************************************************
* Local type definitions ('typedef')
******************************************************************************/
/******************************************************************************
* Local function prototypes ('static')
******************************************************************************/
/******************************************************************************
* Local variable definitions ('static') *
******************************************************************************/
__IO uint8_t flag;
__IO uint8_t second, minute, hour, week, day, month, year;
/*****************************************************************************
* Function implementation - global ('extern') and local ('static')
******************************************************************************/
void App_GpioCfg(void);
void App_RtcCfg(void);
/**
******************************************************************************
** \brief 主函数
**
** @param 无
** \retval 无
**
******************************************************************************/
int32_t main(void)
{
stc_rtc_time_t readtime;
// 设置内部低速时钟的频率
Sysctrl_SetRCLTrim(SysctrlRclFreq32768);
//使能内部低速时钟作为RTC时钟
Sysctrl_ClkSourceEnable(SysctrlClkRCL, TRUE); // 改过 改成内部的
//配置GPIO
App_GpioCfg();
//配置RTC
App_RtcCfg();
while (1)
{
if(flag == 1) // flag在中断中置1
{
flag = 0;
Rtc_ReadDateTime(&readtime); // 获取RTC时钟值
second = readtime.u8Second; // 读取时钟值
minute = readtime.u8Minute;
hour = readtime.u8Hour;
day = readtime.u8Day;
week = readtime.u8DayOfWeek;
month = readtime.u8Month;
year = readtime.u8Year;
//LED 闪烁
if(TRUE == Gpio_GetInputIO(STK_LED_PORT, STK_LED_PIN)) //如果当前LED灯是点亮状态
{
Gpio_WriteOutputIO(STK_LED_PORT, STK_LED_PIN, FALSE); //输出低,熄灭LED
Gpio_WriteOutputIO(GpioPortA, GpioPin5, FALSE); //PA05高电平
}
else //如果当前LED灯是熄灭状态
{
Gpio_WriteOutputIO(STK_LED_PORT, STK_LED_PIN, TRUE); //输出高,点亮LED
Gpio_WriteOutputIO(GpioPortA, GpioPin5, TRUE); //PA05低电平
}
}
}
}
/**
******************************************************************************
** \brief RTC中断入口函数
**
** @param 无
** \retval 无
**
******************************************************************************/
void Rtc_IRQHandler(void)
{
if(Rtc_GetPridItStatus() == TRUE)
{
flag = 1;
Rtc_ClearPrdfItStatus(); //清除中断标志位
}
}
/**
******************************************************************************
** \brief 初始化外部GPIO引脚
**
** \return 无
******************************************************************************/
void App_GpioCfg(void)
{
stc_gpio_cfg_t GpioInitStruct;
DDL_ZERO_STRUCT(GpioInitStruct);
Sysctrl_SetPeripheralGate(SysctrlPeripheralGpio,TRUE); //GPIO外设时钟打开
//Sysctrl_SetPeripheralGate(SysctrlPeripheralTick,TRUE); //GPIO外设时钟打开
//LED指示灯配置
GpioInitStruct.enDrv = GpioDrvH;
GpioInitStruct.enDir = GpioDirOut;
Gpio_Init(STK_LED_PORT, STK_LED_PIN, &GpioInitStruct);
Gpio_WriteOutputIO(STK_LED_PORT, STK_LED_PIN, TRUE); //输出高,点亮LED
//配置PA05引脚和LED控制引脚一样输出,方便示波器观察
Gpio_Init(GpioPortA, GpioPin5, &GpioInitStruct);
}
/**
******************************************************************************
** \brief 配置RTC
**
** @param 无
** \retval 无
**
******************************************************************************/
void App_RtcCfg(void)
{
stc_rtc_initstruct_t RtcInitStruct;
Sysctrl_SetPeripheralGate(SysctrlPeripheralRtc,TRUE);//RTC模块时钟打开
RtcInitStruct.rtcAmpm = RtcPm; //24小时制
RtcInitStruct.rtcClksrc = RtcClkRcl; //内部低速时钟 改过改成内部的
RtcInitStruct.rtcPrdsel.rtcPrdsel = RtcPrdx; //周期中断类型PRDX
RtcInitStruct.rtcPrdsel.rtcPrdx = 1u; //周期中断时间间隔 1秒
RtcInitStruct.rtcTime.u8Second = 0x55; //配置RTC时间
RtcInitStruct.rtcTime.u8Minute = 0x01;
RtcInitStruct.rtcTime.u8Hour = 0x10;
RtcInitStruct.rtcTime.u8Day = 0x17;
RtcInitStruct.rtcTime.u8DayOfWeek = 0x04;
RtcInitStruct.rtcTime.u8Month = 0x04;
RtcInitStruct.rtcTime.u8Year = 0x19;
RtcInitStruct.rtcCompen = RtcCompenEnable; // 使能时钟误差补偿
RtcInitStruct.rtcCompValue = 0; //补偿值 根据实际情况进行补偿
Rtc_Init(&RtcInitStruct);
Rtc_AlmIeCmd(TRUE); //使能闹钟中断
EnableNvic(RTC_IRQn, IrqLevel3, TRUE); //使能RTC中断向量
Rtc_Cmd(TRUE); //使能RTC开始计数
}
/******************************************************************************
* EOF (not truncated)
******************************************************************************/
3.mcu可以工作 ,但是RTC的中断不进去,FLAG不能变成1,感觉使用应该挺规矩的吧 ,不知道那里漏掉了。
4.其它代码都是和DDL库1.9,2一样 |
共1人点赞
|