第22章 系统时间(RTC编程)
来源:互联网 发布:mac装win10会毁电脑吗 编辑:程序博客网 时间:2024/06/05 17:11
取得当前系统时间的方法是直接访问RTC芯片。
RTC芯片可以通过0x70和0x71端口直接访问。0x70是选址寄存器,0x71是数据寄存器。
Addr Function
==== =========================================
** clock/calendar
00 current second for real-time clock
01 alarm second
02 current minute
03 alarm minute
04 current hour
05 alarm hour
06 current day of week (1=Sunday)
07 current date of month
08 current month
09 current year (final two digits; eg, 93)
==== =========================================
** clock/calendar
00 current second for real-time clock
01 alarm second
02 current minute
03 alarm minute
04 current hour
05 alarm hour
06 current day of week (1=Sunday)
07 current date of month
08 current month
09 current year (final two digits; eg, 93)
rtc.h源代码如下所示
#ifndef _RTC_H_#define _RTC_H_#define RTC_REG_ADDR 0x70 //寻址寄存器#define RTC_REG_VALUE 0x71 //内容寄存器#define SECOND_REG 0x0#define MINUTE_REG 0x2#define HOUR_REG 0x4#define DAY_WEEK_REG 0x6#define DAY_MONTH_REG 0x7#define MONTH_REG 0x8#define YEAR_REG 0x9void localtime();#endif
rtc.c源代码如下所示
#include "io.h"#include "rtc.h"#include "video.h"unsigned char get_second(){ outportb(RTC_REG_ADDR, SECOND_REG); return inportb(RTC_REG_VALUE); }unsigned char get_minute(){ outportb(RTC_REG_ADDR, MINUTE_REG); return inportb(RTC_REG_VALUE); }unsigned char get_hour(){ outportb(RTC_REG_ADDR, HOUR_REG); return inportb(RTC_REG_VALUE); }unsigned char get_week_day(){ outportb(RTC_REG_ADDR, DAY_WEEK_REG); return inportb(RTC_REG_VALUE); }unsigned char get_month_day(){ outportb(RTC_REG_ADDR, DAY_MONTH_REG); return inportb(RTC_REG_VALUE); }unsigned char get_month(){ outportb(RTC_REG_ADDR, MONTH_REG); return inportb(RTC_REG_VALUE); }unsigned char get_year(){ outportb(RTC_REG_ADDR, YEAR_REG); return inportb(RTC_REG_VALUE); }void localtime(){ unsigned char s,m,h,dw,dm,mm,y; s = m = h = dw = dm = m = y = 0; s = get_second(); m = get_minute(); h = get_hour(); dw = get_week_day(); dm = get_month_day(); mm = get_month(); y = get_year(); printf("20%x-%x-%x %x %x:%x:%x\n", y,mm,dm, dw, h,m,s);}
- 第22章 系统时间(RTC编程)
- linux系统编程第10章-时间
- RTC何时更新系统时间
- Linux系统时间与RTC时间
- Linux系统时间与RTC时间
- Linux系统时间与RTC时间【转】
- Linux系统时间与RTC时间
- Linux系统时间与RTC时间【转】
- Linux时间系统之RTC时间
- Linux 系统时间 与RTC 时间
- Linux系统时间与RTC时间
- linux 设置系统时间和硬件RTC时间
- linux 设置系统时间和硬件RTC时间
- RTC系统
- RTC系统
- WindowsCE5.0嵌入式系统掉电时间保持问题(RTC)
- STM32L中的系统时间——硬件RTC的使用
- Linux应用层系统时间写入RTC时钟的方法
- 动态链接库和静态链接库的区别
- HDU2136 巧用素数打表法
- TeX系列: dot2tex 和 dot2texi 配置步骤
- IP视频通信中的丢包恢复技术 LPR
- extern与extern "C"
- 第22章 系统时间(RTC编程)
- C 函数的指针与 C++ 函数的指针的不同
- 手动创建UIWindow
- C运行时库(C Run-time Library)详解
- 第23章 扩展任务管理模块
- SQL server中A数据库往B数据库中添加表的操作
- nfs网络服务创建
- 第24章 任务中定时器的设计与实现
- 2011 下学期计划