rtc.h

来自「940时钟程序」· C头文件 代码 · 共 62 行

H
62
字号
#include "types_io.h"
#include "i2c.h"

#ifndef _RTC_H
#define _RTC_H

//#define TO_DEBUG_CUR_TIME				/* print time and date to terminal */

	/**************************************************
	*                                                 *
	*          RTC2025 Control Address                *
	*                                                 *	
	**************************************************/
	#define RTC2025_IIC_ADDRESS_W		0x64
	#define RTC2025_IIC_ADDRESS_R		0x65


	#define INTERNAL_POINTER_ADDRESS 	0xE0
	
	#define READ_CUR_TIME_ADDRESS		0x00
	
	#define READ_CUR_DATE_ADDRESS		0x40
	
	#define WIRTE_TIME_ADDRESS			0x00
	#define WIRTE_DATE_ADDRESS			0x40
	
	/*Control Register1: ADDRESS 0x0E */
	/* WLAE DALE /12.24 /CLEN2 TEST CT2 CT1 CT0*/
	
	#define RTC_CONTROL_REG1_ADDRESS			0x0E
	#define INIT_RTC_CONTROL_REG1				0x20
	
	/*Control Register2: ADDRESS 0x0F */
	/*VDSL VDET /XST PON /CLEN1 CTFG WAFG DAFG*/
	#define RTC_CONTROL_REG2_ADDRESS			0x0F
	#define INIT_RTC_CONTROL_REG2				0x00
	
	/*Time Counter Register(BCD format)*/
	#define RTC_SECOND_COUNTER_ADDRESS			0x00
	#define RTC_MINUTE_COUNTER_ADDRESS			0x01
	#define RTC_HOUR_COUNTER_ADDRESS			0x02
	
	#define RTC_DAY_OF_WEEK_ADDRESS				0x03
	
	#define RTC_DAY_OF_MONTH_ADDRESS			0x04
	#define RTC_MONTH_CENTURY_ADDRESS			0x05
	#define RTC_YEAR_ADDRESS					0x06

	void GetSysTime(void);
	void SetSysTime(UINT hours,UINT minutes,UINT seconds);
	void GetSysDate(void);
	void SetSysDate(UINT years,UINT months,UINT days);
	
	#ifdef TO_DEBUG_CUR_TIME
		void PrintCurTime(void);
		void PrintCurDate(void);
	#endif
	
	void ReadR2025(void);
	BYTE BCDToDec(BYTE bcd_number);
#endif

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?