Two library functions are provided to read and write the real-time clock:

unsigned long

int read_rtc(void)

; //

read bits 15-46 rtc

void write_rtc(unsigned long int

time) ;

//

write bits 15-46

// note: bits

0-14 and bit 47 are zeroed

 

 

However, it is not intended that the real-time clock be read and written frequently. The procedure to read it is lengthy and has an uncertain execution time. The procedure for writing the clock is even more complicated. Instead, Dynamic C software maintains a long variable SEC_TIMER in memory. SEC_TIMER is synchronized with the real-time clock when the Virtual Driver starts, and updated every second by the periodic interrupt. It may be read or written directly by the user’s programs. Since SEC_TIMER is driven by the same oscillator as the real-time clock there is no relative gain or loss of time between the two. A millisecond timer variable, MS_TIMER, is also maintained by the Virtual Driver.

Two utility routines are provided that can be used to convert times between the traditional format (10-Jan-2000 17:34:12) and the seconds since 1-Jan-1980 format.

//converts time structure to seconds unsigned long mktime(struct tm *timeptr);

//seconds to structure

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

The format of the structure used is the following

struct tm {

 

char tm_sec;

// seconds 0-59

char tm_min;

// 0-59

char tm_hour;

// 0-59

char tm_mday;

// 1-31

char tm_mon;

// 1-12

char tm_year;

// 00-150 (1900-2050)

char tm_wday;

// 0-6 0==sunday

};

 

The day of the week is not used to compute the long seconds, but it is generated when computing from long seconds to the structure. A utility program, setclock.c, is avail- able to set the date and time in the real-time clock from the Dynamic C STDIO console.

User’s Manual

245

Page 254
Image 254
Jameco Electronics 3000, 2000 manual Format of the structure used is the following