/**————————————————————
2 〖说明〗I2C总线驱动程序(用两个普通IO模拟I2C总线)
3 包括100Khz(T=10us)的标准模式(慢速模式)选择,
4 和400Khz(T=2.5us)的快速模式选择,
5 默认11.0592Mhz的晶振。
9 〖版本〗V1.00A Build 0803
10 ————————————
/**/
#include /* special function registers */
#include
#define uchar unsigned char
#define uint unsigned int
#define Byte unsigned char
#define Word unsigned int
#define bool bit
#define true 1
#define false 0
uchar SystemError;
#define SomeNOP() _nop_();_nop_();_nop_();_nop_();_nop_();_nop_();
extern void delay(int n);
/**--------------------------------------------------------------------------------
30 调用方式:void I2CStart(void) ﹫2001/07/0 4
31 函数说明:私有函数,I2C专用
32 ---------------------------------------------------------------------------------*/
void I2CStart(void)
{
EA=0;
SDA=1; SCL=1; SomeNOP();//INI
SDA=0; SomeNOP(); //START
SCL=0;
}
/**--------------------------------------------------------------------------------
42 调用方式:void I2CStop(void) ﹫2001/07/0 4
43 函数说明:私有函数,I2C专用
44 ---------------------------------------------------------------------------------*/
void I2CStop(void)
{
SCL=0; SDA=0; SomeNOP(); //INI
SCL=1; SomeNOP(); SDA=1; //STOP
EA=1;
}
/**--------------------------------------------------------------------------------
53 调用方式:bit I2CAck(void) ﹫2001/07/0 4
54 函数说明:私有函数,I2C专用,等待从器件接收方的应答
55 ---------------------------------------------------------------------------------*/
bool WaitAck(void)
{
uchar errtime=255;//因故障接收方无ACK,超时值为255。
SDA=1;SomeNOP();
SCL=1;SomeNOP();
while(SDA) {errtime--; if (!errtime) {I2CStop();SystemError=0x11;return false;}}
SCL=0;
return true;
//第1 页
//文件: PCF8563T.C 2001-11-27, 18:39:20
}
/**---------------------------------------------------------------