有一段时间没碰pc上的汇编了,忘了好多,今天老师让我们写个读取cmos时钟的程序,也让我折腾了半天,关键的原因如前所述。
找了半天书,写了个简单的程序。后来又Baidu了下,找了个linux下c语言版的,感觉不错,比较好懂,这里贴出来,自己写的汇编的感觉还不是很好先不发了。
程序如下,
#include <stdio.h>
#include <linux/rtc.h>
#include <sys/ioctl.h>
#include <sys/time.h>
#include <sys/types.h>
#include <fcntl.h>
#include <unistd.h>
#include <errno.h>
int main(void)
{
int i, fd, retval, irqcount = 0;
unsigned long tmp, data;
struct rtc_time rtc_tm;
fd = open ("/dev/rtc", O_RDONLY);
if (fd == -1) {
perror("/dev/rtc");
exit(errno);
}
fprintf(stderr, "\n\t\t\tRTC Driver Test Example.\n\n");
/* Read the RTC time/date */
retval = ioctl(fd, RTC_RD_TIME, &rtc_tm);
if (retval == -1) {
perror("ioctl");
exit(errno);
}
fprintf(stderr, "\n\nCurrent RTC date/time is %d-%d-%d, %02d:%02d:% 02d.\n", rtc_tm.tm_mday, rtc_tm.tm_mon + 1, rtc_tm.tm_year + 1900,
rtc_tm.tm_hour, rtc_tm.tm_min, rtc_tm.tm_sec);
close(fd);
return 0;
}
以上的程序感觉还比较好懂,自己还没编译,感觉应该可以的
-------------------------------------以上程序来自从Baidu搜到的某人的博客