看就是有看过编程规范的-ds1302 程序

来源:互联网 发布:unity3d怎么模拟场景 编辑:程序博客网 时间:2024/04/28 21:49

http://www.ourdev.cn/bbs/bbs_content.jsp?bbs_sn=5245747&bbs_page_no=1&search_mode=1&search_text=1302&bbs_id=9999

 

*--------------------------------------------------------------------
函数名称:DS1302的一个完整写操作
函数功能:
注意事项:无
提示说明:无
输    入:
返    回:无
--------------------------------------------------------------------*/
void write(uint8 addr,uint8 dat)
{
CLR_RST;    //before SCL change to low level, RST must keep low level
CLR_SCK;
SET_RST;

//CLR_SCK;    //also ok!!!
//CLR_RST;
//SET_RST;

//CLR_RST;    //error
//SET_RST;
//CLR_SCK;

operData=0X80|(addr<<1);
writeByte();
operData=dat;
writeByte();
/* the following sentence here is not indispensable,
   but insert this sentence here can prevent ariseing error!
   because when start operating,RST must keep low level! */
CLR_RST;
}
/*--------------------------------------------------------------------
函数名称:DS1302的一个完整读操作
函数功能:
注意事项:无
提示说明:无
输    入:
返    回:无
--------------------------------------------------------------------*/
uint8 read(uint8 cmd)
{
//CLR_RST;
CLR_SCK;
SET_RST;
operData=(cmd<<1)|0x81;
writeByte();
readByte();
/* the following sentence here is not indispensable,
   but insert this sentence here can prevent ariseing error!
   because when start operating,RST must keep low level! */
CLR_RST;
return(operData); 
}
/*--------------------------------------------------------------------
函数名称:DS1302读时间
函数功能:
注意事项:无
提示说明:无
输    入:
返    回:无
--------------------------------------------------------------------*/
void DS1302_getTime(uint8 *buf)
{
uint8 hourAdr=2,minuteAdr=1,secondAdr=0;

buf[0]=read(secondAdr);
buf[0]=changeHexToInt(buf[0]);

buf[1]=read(minuteAdr);
buf[1]=changeHexToInt(buf[1]);

buf[2]=read(hourAdr);
buf[2]=changeHexToInt(buf[2]);

//DS1302_speaTime();
}
/*--------------------------------------------------------------------
函数名称:DS1302读日期
函数功能:
注意事项:无
提示说明:无
输    入:无
返    回:无
--------------------------------------------------------------------*/
//void DS1302_getDate(void)
//{
//
//}
/*--------------------------------------------------------------------
函数名称:DS1302拆时间
函数功能:
注意事项:无
提示说明:低层将时间拆好,方便上层调用
输    入:无
返    回:无
--------------------------------------------------------------------*/
//void DS1302_speaTime(void)
//{
// speaData(DS1302Second,2);
// DS1302SecHi=dataElem[1];
// DS1302SecLow=dataElem[0];
//
// speaData(DS1302Minute,2);
// DS1302MinHi=dataElem[1];
// DS1302MinLow=dataElem[0];
//
// speaData(DS1302Hour,2);
// DS1302HourHi=dataElem[1];
// DS1302HourLow=dataElem[0];
//}
/*--------------------------------------------------------------------
函数名称:DS1302拆日期
函数功能:
注意事项:无
提示说明:无
输    入:无
返    回:无
--------------------------------------------------------------------*/
//void DS1302_speaDate(void)
//{
//
//}
/*--------------------------------------------------------------------
函数名称:DS1302设置时间
函数功能:
注意事项:无
提示说明:无
输    入:
返    回:无
--------------------------------------------------------------------*/
void DS1302_setTime(uint8 hour,uint8 minute,uint8 second)
{
uint8 hourAdr=2,minuteAdr=1,secondAdr=0;

hour=changeIntToHex(hour);
minute=changeIntToHex(minute);
second=changeIntToHex(second);

openWP();
write(hourAdr,hour);
write(minuteAdr,minute);
write(secondAdr,second);
closeWP();
}
/*--------------------------------------------------------------------
函数名称:DS1302设置日期
函数功能:
注意事项:无
提示说明:无
输    入:
返    回:无
--------------------------------------------------------------------*/
//void DS1302_setDate(uint8 year,uint8 month,uint8 day)
//{
//
//}
/*--------------------------------------------------------------------
函数名称:DS1302初始化
函数功能:
注意事项:无
提示说明:无
输    入:无
返    回:无
--------------------------------------------------------------------*/
void DS1302_init(void)
{
OUT_SCK;
OUT_SIO;
OUT_RST;
openWP();
setChargePrmt();
closeWP();
}

#endif

原创粉丝点击