我正在为 Raspberry Pi 使用 Busware 的扩展程序 SD0
。它上面是 OS Raspbian。 Raspberry Pi 没有互联网连接。 SD0 包含 RTC ds1338
。
如何用C或C++语言设置树莓派的时间和日期?
我或多或少知道如何通过 I2C 连接。
最佳答案
您始终可以在 C 代码中调用命令行工具:
settimeofday(timeval, NULL);
system("hwclock --systohc")
或者您可以通过 ioctl 接口(interface)直接访问您的 rtc 设备驱动程序。 ( http://lxr.free-electrons.com/source/include/uapi/linux/rtc.h )
例子:
struct rtc_time rtc = {};
tnow.tm_year = 2015; /* fill up entire struct */
int fd = open("/dev/rtc0", O_RDWR)
ioctl(fd, RTC_SET_TIME, &tnow);
close(fd);
关于c++ - 如何用c在树莓派上设置时间和日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31454905/