当前位置: 技术问答>linux和unix
如何用程序修改BIOS时钟
来源: 互联网 发布时间:2015-08-17
本文导语: 我想修改BIOS时钟,用hwclock命令是可以,但我想知道如何用代码来实现hwclock的功能。谢谢 | 修改BIOS时钟(需要简单修改): ret = ioperm (0x70,2,1); if (ret == -1) { #ifdef T_DEBUG...
我想修改BIOS时钟,用hwclock命令是可以,但我想知道如何用代码来实现hwclock的功能。谢谢
|
修改BIOS时钟(需要简单修改):
ret = ioperm (0x70,2,1);
if (ret == -1)
{
#ifdef T_DEBUG
printf("Synchronizate Sys Time--get right errorn");
#endif
return TongFalse;
}
outb(0x00, 0x70);
outb(InttoBCD(atoi(second)), 0x71); //sec
outb(0x02, 0x70);
outb(InttoBCD(atoi(minute)), 0x71); //min
outb(0x04, 0x70);
outb(InttoBCD(atoi(hour)), 0x71); //hour
outb(0x07, 0x70);
outb(InttoBCD(atoi(day)), 0x71); //day
outb(0x08, 0x70);
outb(InttoBCD(atoi(month)), 0x71); //month
outb(0x09, 0x70);
outb(InttoBCD(atoi(year)), 0x71); //year
ret = ioperm (0x70,2,0);
if (ret == -1)
{
#ifdef T_DEBUG
printf("Synchronizate Sys Time--free right errorn");
#endif
return False;
}
注意:在编译该函数时,编译器需要加上-O2等优化参数
ret = ioperm (0x70,2,1);
if (ret == -1)
{
#ifdef T_DEBUG
printf("Synchronizate Sys Time--get right errorn");
#endif
return TongFalse;
}
outb(0x00, 0x70);
outb(InttoBCD(atoi(second)), 0x71); //sec
outb(0x02, 0x70);
outb(InttoBCD(atoi(minute)), 0x71); //min
outb(0x04, 0x70);
outb(InttoBCD(atoi(hour)), 0x71); //hour
outb(0x07, 0x70);
outb(InttoBCD(atoi(day)), 0x71); //day
outb(0x08, 0x70);
outb(InttoBCD(atoi(month)), 0x71); //month
outb(0x09, 0x70);
outb(InttoBCD(atoi(year)), 0x71); //year
ret = ioperm (0x70,2,0);
if (ret == -1)
{
#ifdef T_DEBUG
printf("Synchronizate Sys Time--free right errorn");
#endif
return False;
}
注意:在编译该函数时,编译器需要加上-O2等优化参数
|
system("hwclock");
呵呵
呵呵