打印
[demo程序]

NV32F101 RTC定时中断程序示例

[复制链接]
786|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
Bruing|  楼主 | 2018-8-28 18:33 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
/**********************************************************************
*
* 实验名称:RTC定时中断
* 实验平台:NV32开发板
* 板载芯片:NV32F101FL64E
* 实验效果:RTC时钟源选择LPOCLK-1KHZ,板载LED闪烁        
*
************************************************************************/

#include "common.h"
#include "rtc.h"
#include "uart.h"
#include "sysinit.h"

int main (void);
void RTC_Task(void);


uint8_t i=0;
/********************************************************************/
int main (void)
{
    uint8_t u8Ch;
    uint16_t u16ModuloValue;
    RTC_ConfigType  sRTCConfig;
    RTC_ConfigType  *pRTC_Config=&sRTCConfig;


    /* 系统初始化 */
    sysinit();

    printf("\nRunning the RTC_demo project.\r\n");
    LED0_Init();  
    LED1_Init();
    LED2_Init();
   
    /* 配置RTC的中断频率为1HZ */
    u16ModuloValue = 0x09;//模值为10
    pRTC_Config->u16ModuloValue = u16ModuloValue;//装载值到模数寄存器中
    pRTC_Config->bInterruptEn   = RTC_INTERRUPT_ENABLE;    //使能中断
    pRTC_Config->bClockSource   = RTC_CLKSRC_1KHZ;         //选取时钟源为1KHZ
    pRTC_Config->bClockPresaler = RTC_CLK_PRESCALER_100;   //分频数为100
    RTC_SetCallback(RTC_Task);
    RTC_Init(pRTC_Config);
       
    while(1)
    {
       u8Ch = UART_GetChar(TERM_PORT);
       UART_PutChar(TERM_PORT, u8Ch);
    }
}

/*****************************************************************************//*!
*
* @RTC中断任务函数,闪烁LED,三个LED轮点
*      
* @无返回
*
*****************************************************************************/

void RTC_Task(void)
{       
        i=i+1;

        if(i%3==2)
        {
                LED0_On();  
                LED1_Off();
                LED2_Off();
        }
        else if(i%3==1)
        {
                LED0_Off();
                LED1_On();
                LED2_Off();
        }
else
        {
                LED0_Off();
                LED1_Off();
                LED2_On();  
        }

}
/********************************************************************/


相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

71

主题

308

帖子

1

粉丝