AMC 68VZ328 software manual

Models: 68VZ328

1 115
Download 115 pages 46.92 Kb
Page 51
Image 51

}

This program will read the date from the kernel clock and print it out to the standard output stream.

//date.c

//This will read the date from the realtime clock and

//display it on screen.

#include <stdio.h> #include <sys/time.h> #include <unistd.h> void main() {

struct timeval time_val;

//read the date from the realtime clock gettimeofday(&time_val, NULL);

//display the value from the clock

printf(“%s”, ctime((time_t *) &time_val.tv_sec));

}

The following program writes a given date to the kernel clock and then commits it to the hard- ware real-time clock.

//rtc.c

//This program will first set the date on the real time clock

to

//Fri May 25 10:21:00 2001 and then read it back and display

it.

#include <stdio.h> #include <sys/time.h> #include <unistd.h> void main ()

{

struct timeval time_val; struct tm tm_val;

//load the time we are setting into the time structure tm_val.tm_sec = 0;

tm_val.tm_min = 21; tm_val.tm_hour = 10; tm_val.tm_mday = 25; tm_val.tm_mon = 4; tm_val.tm_year = 2001 - 1900; tm_val.tm_wday = 5;

www.amctechcorp.com

51

Page 51
Image 51
AMC 68VZ328 software manual