?? pcf8563.h
字號:
/*********************************************************************
微 雪 電 子 WaveShare http://www.waveShare.net
目 的: 建立PCF8563操作庫
目標(biāo)系統(tǒng): 基于AVR單片機(jī)
應(yīng)用軟件: ICCAVR
版 本: Version 1.0
圓版時間: 2005-06-25
開發(fā)人員: SEE
說 明: 若用于商業(yè)用途,請保留此段文字或注明代碼來源
深 圳 微 雪 電 子 保 留 所 有 的 版 權(quán)
*********************************************************************/
/*01010101010101010101010101010101010101010101010101010101010101010101
----------------------------------------------------------------------
版本更新記錄:
----------------------------------------------------------------------
入口參數(shù)說明:
//#define WR_DADR 0xA2 //器件地址:A2 A1 A0 = 0 0 0
//#define RD_DADR 0xA3 //器件地址:A2 A1 A0 = 0 0 0
----------------------------------------------------------------------
待定參數(shù)說明:
----------------------------------------------------------------------
對外變量說明:
----------------------------------------------------------------------
對外函數(shù)說明:
----------------------------------------------------------------------
10101010101010101010101010101010101010101010101010101010101010101010*/
#ifndef PCF8563_H
#define PCF8563_H
#include "E:\ICC_H\CmmICC.H"
#include "E:\ICC_H\I2C.H"
//器件地址:A0 A1 A2 = 0 0 0
#ifndef WR_DADR
#define WR_DADR 0xA2 //write device-address
#endif
#ifndef RD_DADR
#define RD_DADR 0xA3 //read device-address
#endif
#define CTRL_BUF1 0x00
#define CTRL_BUF2 0x01
#define SECOND_DATA_BUF 0x02
#define MINUTE_DATA_BUF 0x03
#define HOUR_DATA_BUF 0x04
#define DAY_DATA_BUF 0x05
#define WEEK_DATA_BUF 0x06
#define MONTH_DATA_BUF 0x07
#define YEAR_DATA_BUF 0x08
#define MINUTE_AE_BUF 0x09
#define HOUR_AE_BUF 0x0A
#define DAY_AE_BUF 0x0B
#define WEEK_AE_BUF 0x0C
#define CLK_FRQ_BUF 0x0D
#define TIMER_CTRL_BUF 0x0E
#define COUNT_VAL_BUF 0x0F
#define PCF8563_ERR 0
#define PCF8563_CRR 1
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:寫 1個 Byte 到相應(yīng)的寄存器
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
bool WriteAByte(uint8 wordAdr,uint8 dat)
{
if( I2C_Write(WR_DADR,wordAdr,dat)==I2C_ERR )
return I2C_ERR;
return I2C_CRR;
}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:寫 N個 Byte 到相應(yīng)的寄存器
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
//void WriteNByte(uint8 wordAdr,uint8 num,uint8 *pWrDat)
//{
//
//}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:讀 1個 Byte 到相應(yīng)的寄存器
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
//void ReadAByte(uint8 wordAdr,uint8 *pRdDat)
//{
// I2C_Start();
//
// I2C_SendByte(WR_DADR);
// I2C_WaitAck();
//
// I2C_SendByte(wordAdr);
// I2C_WaitAck();
//
// I2C_Start();
//
// I2C_SendByte(RD_DADR);
// I2C_WaitAck();
//
// I2C_RcvByte(pRdDat);
// I2C_SendNoAck();
//
// I2C_Stop();
//}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:讀 N個 Byte 到相應(yīng)的寄存器
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
bool ReadNByte(uint8 wordAdr,uint8 *pRdDat,uint8 num)
{
if( I2C_Read_(WR_DADR,wordAdr,RD_DADR,pRdDat,num)==I2C_ERR )
return I2C_ERR;
return I2C_CRR;
}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:獲取PCF8563的時間
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
void PCF8563_getTime(uint8 *buf)
{
//ReadAgain:
ReadNByte(SECOND_DATA_BUF,buf,3);
buf[0]=buf[0]&0x7f; //get second data
//if(buf[0]==0)
//goto ReadAgain; //if "second==0",read again for avoid mistake
buf[1]=buf[1]&0x7f; //get minute data
buf[2]=buf[2]&0x3f; //get hour data
buf[0]=changeHexToInt(buf[0]);
buf[1]=changeHexToInt(buf[1]);
buf[2]=changeHexToInt(buf[2]);
}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:設(shè)置PCF8563的時間
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
void PCF8563_setTime(uint8 hour,uint8 minute,uint8 second)
{
hour=changeIntToHex(hour); //將數(shù)據(jù)的Dex格式轉(zhuǎn)換為Hex格式
minute=changeIntToHex(minute);
second=changeIntToHex(second);
WriteAByte(HOUR_DATA_BUF,hour);
WriteAByte(MINUTE_DATA_BUF,minute);
WriteAByte(SECOND_DATA_BUF,second);
}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:獲取PCF8563的日期
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
//void PCF8563_getDate()
//{
//
//}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:設(shè)置PCF8563的日期
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
//void PCF8563_setDate()
//{
//
//}
/*--------------------------------------------------------------------
函數(shù)名稱:
函數(shù)功能:初始化PCF8563
注意事項:
提示說明:
輸 入:
返 回:
--------------------------------------------------------------------*/
void PCF8563_init()
{
WriteAByte(CTRL_BUF1,0x00); //basic setting
WriteAByte(CTRL_BUF2,0x12); //alarm enable
//WriteAByte(HOUR_AE_BUF,0x09); //set alarm hour at 9:00
//WriteAByte(CLK_FRQ_BUF,0xf0); //set clkout frequency
}
#endif
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -