用于跟踪日期的 AVR 库/片段
有谁知道可用于在嵌入式环境(AVR MCU)中存储/跟踪时间和日期的库或良好的代码片段。我希望能够设置日期和时间,然后使用我的一个计时器的 1hz 脉冲进行更新。我可以自己编写这段代码,但我觉得可能已经有一些东西了。
Does anyone know of a library or good code snippit that can be used to store/keep track of time and date within an embedded environment (AVR MCU). I would like to be able to set a date and time and then update it using a 1hz pulse from one of my timers. I could write this code myself however I feel like there may already be something out there.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
通常您会使用 RTC 来实现此目的,因为 AVR 的 1Hz 脉冲并不那么精确。执行此操作的正常方法是制作当前时间的时间戳并每秒增加它。您可以使用 mktime 方法来创建时间戳,尽管我不确定 AVR libc 是否支持它。 http://www.manpagez.com/man/3/mktime/ 当您想要将其转换回“正常”时间,您可以使用
ctime
作为可打印版本,或使用gmtime
作为struct tm
版本。Normally you would use a RTC for this because the 1Hz pulse of the AVR is not that precise. A normal way to do this is to make a time stamp of the current time and increase it every second. You can make a timestamp by using the method
mktime
although I'm not sure it's supported supported in the AVR libc. http://www.manpagez.com/man/3/mktime/ When you want to convert it back to 'normal' time you could usectime
for the printable version orgmtime
for thestruct tm
version.有 Arduino 时间库。但我从未使用过它。
There is the Arduino Time library. I never used it though.
我最终做的是采用苹果使用的
time.h
库,并根据我的项目稍微调整它,因为它是在 BSD 许可证下的。可以在此处找到What I ended up doing was taking the
time.h
library that was used by apple and adapting it slightly for my project as it was under the BSD licence. It can be found Here