View Full Version : Real-Time Clock
Kevin777
02-17-2008, 11:24 PM
Hello,
I am trying to use the Real-Time Clock function read_rtc,
unsigned long read_rtc( void );
I've tried,
/*** Start Code ***/
void main()
{
unsigned long x,y;
int i;
i = 0;
x=read_rtc();
while(i<10)
{ ++i; }
y=read_rtc();
printf("x = %u", x);
printf("y = %u", y);
}
/*** End Code ***/
but it fails.
Please show me how to use this function.
ideaman4u
02-18-2008, 11:28 PM
I recommend that you not use this function. Instead, assuming you need date broken out, use mktm() to load a time struct from SEC_TIMER. This assumes that you have used mktime() and write_rtc() to set the timer with a RCM or SBC that has a backup battery or every time after a power cycle.
It is better not to directly access the RTC if you don't REALLY need to.
Kevin777
02-21-2008, 06:39 PM
I recommend that you not use this function. Instead, assuming you need date broken out, use mktm() to load a time struct from SEC_TIMER. This assumes that you have used mktime() and write_rtc() to set the timer with a RCM or SBC that has a backup battery or every time after a power cycle.
It is better not to directly access the RTC if you don't REALLY need to.
I appreciate your advice!
I wrote a program to implement mktm(), however after compilation all that appeared was my code with green highlighting over one of my variables(shown below).
Code Start
void main()
{
//unsigned int mktm( struct tm *timeptr, unsigned long time );
unsigned int x,y,t;
struct tm *p;
int i;
t = 0; // *** highlighted variable ***
i = 0;
x=mktm( p,t);
printf("going to while...\n");
while(i<100)
{ ++i; }
y=mktm( p,t );
printf("x = %u\n", x);
printf("y = %u\n", y);
}
Code End
Am I using the struct *tm correctly? How about the mktm()?
vBulletin® v3.7.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.