读RTC出错
时间:2007-08-14
来源:互联网
本人在2410上运行一段读RTC程序,开始的二十分钟可以读,时间不段更新,但过了一段时间后读出来的数据就不变了,即时间一直停留在过去某一时刻,下面是我的程序,请大侠们指点一下阿,万分感谢:
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(void)
{
while(1)
{
int fd,size;
int gd,sd[8],m;
char hour,min,sec,month,day;
unsigned char tr[25];
int year;
char time[30];
float rd[8];
fd=open("/proc/driver/rtc",O_RDONLY);
lseek(fd,11,SEEK_SET);
read(fd,time,30);
year=(time[20]-48)*1000+(time[21]-48)*100+(time[22]-48)*10+time[23]-48;
month=(time[25]-48)*10+time[26]-48;
day=(time[28]-48)*10+time[29]-48;
hour=(time[0]-48)*10+time[1]-48;
min=(time[3]-48)*10+time[4]-48;
sec=(time[6]-48)*10+time[7]-48;
printf("the year is:%d\n",year);
printf("the month is:%d\n",month);
printf("the day is:%d\n",day);
printf("the hour is:%d\n",hour);
printf("the min is:%d\n",min);
printf("the sec is:%d\n",sec);
sleep ( 1 );
close ( fd );
}
}
#include<unistd.h>
#include<sys/types.h>
#include<sys/stat.h>
#include<fcntl.h>
#include<stdlib.h>
#include<stdio.h>
#include<string.h>
#include <stdlib.h>
int main(void)
{
while(1)
{
int fd,size;
int gd,sd[8],m;
char hour,min,sec,month,day;
unsigned char tr[25];
int year;
char time[30];
float rd[8];
fd=open("/proc/driver/rtc",O_RDONLY);
lseek(fd,11,SEEK_SET);
read(fd,time,30);
year=(time[20]-48)*1000+(time[21]-48)*100+(time[22]-48)*10+time[23]-48;
month=(time[25]-48)*10+time[26]-48;
day=(time[28]-48)*10+time[29]-48;
hour=(time[0]-48)*10+time[1]-48;
min=(time[3]-48)*10+time[4]-48;
sec=(time[6]-48)*10+time[7]-48;
printf("the year is:%d\n",year);
printf("the month is:%d\n",month);
printf("the day is:%d\n",day);
printf("the hour is:%d\n",hour);
printf("the min is:%d\n",min);
printf("the sec is:%d\n",sec);
sleep ( 1 );
close ( fd );
}
}
作者: lyl_allen 发布时间: 2007-08-14
20分钟之前关闭再重新打开
如此overoll
如此overoll
作者: AIKO_sex 发布时间: 2007-08-14
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28