#include "includes.h"

void RTC_Reset(void)
{
	RESET=1;
	_NOP();
	RESET=0;
	_NOP();
}

unsigned char bcd_to_hex(unsigned char data_in)
{
    unsigned char temp;
    temp = ((data_in>>4)*10 + (data_in&0x0f));
    return temp;
}

unsigned char hex_to_bcd(unsigned char hex)
{
	unsigned char bcd;
	bcd=(hex/10)*16+(hex%10);
	return bcd;
}

void RTC_Configuration(void)
{
	RTCSRT = RTC_Disable;			//停止RTC
	RTC_Reset();					//RTC逻辑复位
	RTCTTR=RTC_OUT_enable|RTC_OUT_SEL_TTR|RTCTTR_SEL_1_S; 		//RTC节拍中断1s

	RTCALREN = 0;		//禁止闹钟
	HT=0;		 	 	//24小时制
	TMR0EN = 0;			//禁止T0
	TMR1EN = 0;			//禁止T1
	while(!RTOFF);
	CNF=1;	     		 //进入写模式
	while(!RTOFF);
	RTCSEC=0; 			//秒
	while(!RTOFF);
	RTCMIN=0; 			//分
	while(!RTOFF);
	RTCHOUR=0; 			//分
	while(!RTOFF);
	CNF=0;		  //写入
	while(!RTOFF);//等待写完成

//	PTT=1;	      		//高优先级
	TTIF=0;
	TTIE=1;      		//使能时间节拍中断
	RTCSRT = RTC_Enable;	//启动RTC
}
