通过PC标定开发板时间及更新间隔

通过PC标定开发板时间及更新间隔。
‏PC通过串口发送日期时间(格式自己指定,比如2022-03-05 22:33:23/5),开发板接收到时间后设置rtc. 并用定时器中断,每隔5s打印当前时间。
实验过程
1、编译代码,生成RTC.bin文件
2、连接开发板。查看端口。
在这里插入图片描述
3、打开putty
在这里插入图片描述
在这里插入图片描述
4、通电
5、打开NuWriter
在这里插入图片描述
在这里插入图片描述
烧录
6、拔掉帽 USB->NAND
7、选择reset
8、打印时间
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
main.c(编译代码,生成RTC.bin文件)

#include <stdio.h>
#include "nuc970.h"
#include "sys.h"
#include "rtc.h"

/*---------------------------------------------------------------------------------------------------------*/
/* Global variables                                                                                        */
/*---------------------------------------------------------------------------------------------------------*/
UINT32 volatile g_u32TICK = 0;
BOOL volatile g_bAlarm = FALSE;
VOID Smpl_RTC_Powerdown_Wakeup(void);
VOID Smpl_RTC_Powerdown_Wakeup_Relative(void);
VOID Smpl_RTC_PowerOff_Control(UINT32 u32Mode);

#define HW_POWER_OFF	0
#define SW_POWER_OFF	1

/*---------------------------------------------------------------------------------------------------------*/
/* RTC Tick Callback function                                                                             */
/*---------------------------------------------------------------------------------------------------------*/
VOID RTC_TickISR(void)
{
	RTC_TIME_DATA_T sCurTime;
	
	/* Get the currnet time */
	RTC_Read(RTC_CURRENT_TIME, &sCurTime);		
	if(g_u32TICK%5==0&&g_u32TICK>1)
		sysprintf("   Current Time:%d/%02d/%02d %02d:%02d:%02d\n",sCurTime.u32Year,sCurTime.u32cMonth,sCurTime.u32cDay,sCurTime.u32cHour,sCurTime.u32cMinute,sCurTime.u32cSecond);				
	RTC_EnableClock(TRUE);
	g_u32TICK++;
}

/*---------------------------------------------------------------------------------------------------------*/
/* RTC Alarm Callback function                                                                             */
/*---------------------------------------------------------------------------------------------------------*/
VOID RTC_AlarmISR(void)
{
	
	sysprintf("   Abolute Alarm!!\n");
	
	g_bAlarm = TRUE; 
}

VOID RTC_Releative_AlarmISR(void)
{
	
	sysprintf("   Relative Alarm!!\n");
	
	g_bAlarm = TRUE; 
}

int main()
{
	//UINT32 u32Item, u32ExtFreq;
	UINT32 u32Item;
	RTC_TIME_DATA_T sInitTime;
	//UINT32 u32ClockSource;
		
	sysDisableCache();
    sysFlushCache(I_D_CACHE);
    sysEnableCache(CACHE_WRITE_BACK);
    sysInitializeUART();

	RTC_EnableClock(TRUE);
	
	/* RTC Initialize */
	RTC_Init();	
	
	/* Time Setting */
	sInitTime.u32Year = 2022;
	sInitTime.u32cMonth = 3;	
	sInitTime.u32cDay = 17;
	sInitTime.u32cHour = 20;
	sInitTime.u32cMinute = 30;
	sInitTime.u32cSecond = 0;
	sInitTime.u32cDayOfWeek = RTC_TUESDAY;
	sInitTime.u8cClockDisplay = RTC_CLOCK_24;			

	/* Initialization the RTC timer */
	if(RTC_Open(&sInitTime) !=E_RTC_SUCCESS)
		sysprintf("Open Fail!!\n");
			
	sysSetLocalInterrupt(ENABLE_IRQ);	
	
	sysprintf("Do RTC Calibration \n");	
	RTC_Ioctl(0,RTC_IOC_SET_FREQUENCY, 0,0);	
	
	do
	{    	
		sysprintf("=======================================\n");
		sysprintf("             RTC Demo Code	          \n"); 	
		sysprintf("=======================================\n");	
		sysprintf("      (Clock from External 32K Hz)     \n");  			
		sysprintf("=======================================\n");	
		sysprintf("Select Demo Item:\n");
		sysprintf("0. Time Display Test\n");
		sysprintf("Q. Exit\n");
		u32Item = sysGetChar();			
		
		switch(u32Item)
		{
			case '0':
			{
				RTC_TICK_T sTick;
				
				sysprintf("\n0. RTC Time Display Test (Exit after 5 seconds)\n");
					
				/* Set Tick property */
				sTick.ucMode = RTC_TICK_1_SEC;
				sTick.pfnTickCallBack = RTC_TickISR;		
				
				/* Set Tick setting */
				RTC_Ioctl(0,RTC_IOC_SET_TICK_MODE, (UINT32)&sTick,0);

				/* Enable RTC Tick Interrupt and install tick call back function */
				RTC_Ioctl(0,RTC_IOC_ENABLE_INT, (UINT32)RTC_TICK_INT,0);	
				
				g_u32TICK = 0;
				
				RTC_EnableClock(TRUE);
				
				while(g_u32TICK < 26);
				
				RTC_EnableClock(FALSE);

				/* Disable RTC Tick Interrupt */
				RTC_Ioctl(0,RTC_IOC_DISABLE_INT, (UINT32)RTC_TICK_INT,0);							
				break;
			}							
			default:
				sysprintf("Wrong Item\n");
				break;			
		}
		
	}while((u32Item!= 'q') || (u32Item!= 'Q'));	
			
	
	/* Disable RTC  */		
	RTC_Close();
	
	/* Disable I & F bit */ 
	sysSetLocalInterrupt(DISABLE_IRQ);		
}  
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值