Real-Time Clock

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.

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 agree with ideaman don’t use rtc()

[QUOTE=ideaman4u;1355]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.[/quote]

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…
");
while(i<100)
{ ++i; }
y=mktm( p,t );
printf("x = %u
", x);
printf("y = %u
", y);
}

Code End

Am I using the struct *tm correctly? How about the mktm()?

[QUOTE=Kevin777;1374]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…
");
while(i<100)
{ ++i; }
y=mktm( p,t );
printf("x = %u
", x);
printf("y = %u
", y);
}

Code End

Am I using the struct *tm correctly? How about the mktm()?[/quote]

mktm

SYNTAX: unsigned int mktm(struct tm *timeptr, unsigned long time)

KEYWORDS: Real-time clock

DESCRIPTION: Converts the seconds to date and time.

PARAMETER1: Address of tm struct to store date and time.
PARAMETER2: Seconds since January 1, 1980.

RETURN VALUE: Zero.

Note you are attempting to pass an unsigned integer “t” where a long is expected.