+ -
当前位置:首页 → 问答吧 → 读RTC出错

读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 );
}
}      

作者: lyl_allen   发布时间: 2007-08-14

20分钟之前关闭再重新打开

如此overoll

      

作者: AIKO_sex   发布时间: 2007-08-14