📄 rtcdemo.c
字号:
/*****************************************************************************
* $Workfile: rtcdemo.c $
* $Revision: 1.0 $
* $Author: WellsK $
* $Date: Sep 22 2002 11:00:08 $
*
* Project: RTC time conversion example
*
* Description:
* This example converts the RTC count (stored in epoch time format) to a
* formatted time string.
*
* Revision History:
* $Log: //smaicnt2/pvcs/VM/CDROM/archives/KEV7A400/Software/Examples/rtcdemo/rtcdemo.c-arc $
*
* Rev 1.0 Sep 22 2002 11:00:08 WellsK
* Initial revision.
*
*
* COPYRIGHT (C) 2001 SHARP MICROELECTRONICS OF THE AMERICAS, INC.
* CAMAS, WA
****************************************************************************/
#include "simple_RTC.h"
#include "epoch_time.h"
#include <stdio.h>
int main (void)
{
INT_32 month, day, year, hour, minute, second;
UNS_32 input_epoch, present_epoch, old_epoch;
// Start by enabling the RTC and showing the present 'time' stored
// in the RTC. On the first instance of this program, the RTC clock
// value may be undefined.
RTC_Enable ();
printf ("The present RTC time is : ");
Time_Show (RTC_Get_Count ());
printf ("\n");
// Prompt the user for the present time and date information
printf ("Enter the present year (2002):");
scanf ("%d", &year);
printf ("Enter the present month (1 - 12):");
scanf ("%d", &month);
printf ("Enter the present day (1 - 31):");
scanf ("%d", &day);
printf ("Enter the local hour (0 - 23):");
scanf ("%d", &hour);
printf ("Enter the local minute (0 - 59):");
scanf ("%d", &minute);
printf ("Enter the local second (0 - 59):");
scanf ("%d", &second);
// Convert the input time to an equivalent epoch time
input_epoch = Time_Convert_To_Epoch (year, month, day, hour,
minute, second);
// Put the epoch time into the RTC so it will stay updated
RTC_Set_Count (input_epoch);
// The count was loaded into the RTC count load register, but
// will NOT be available until the next RTC clock tick. On the
// next RTC clock, the load value plus one will move into the
// RTC count register. To prevent possible time display problems
// or bad counts, wait until the timer updates to the correct
// input_epoch value
printf ("Waiting for RTC count to sync to RTC load...\n");
while ((input_epoch + 1) != RTC_Get_Count ());
printf ("Sync'd!\n");
// Show the input time every second and quit after 10 seconds
present_epoch = RTC_Get_Count ();
old_epoch = input_epoch;
while (present_epoch < (input_epoch + 10))
{
if (old_epoch != present_epoch)
{
// Only display the time when it changes
old_epoch = present_epoch;
printf ("Epoch time : %d, local time : ", present_epoch);
Time_Show (present_epoch);
printf ("\n");
}
present_epoch = RTC_Get_Count ();
}
return 1;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -