工业控制 | 能源技术 | 汽车电子 | 通信网络 | 安防监控 | 智能电网 | 移动手持 | 无线技术 | 家用电器 | 数字广播 | 消费电子 | 应用软件 | 其他方案

PCF8563 I2C驱动(C)

作者:dolphin 时间:2012-10-31

1 /**————————————————————
2
〖说明〗 I2C总线驱动程序 (用两个普通 IO模拟 I2C总线 )
3
包括 100Khz(T=10us)的标准模式 (慢速模式 )选择,
4400Khz(T=2.5us)的快速模式选择,
5默认 11.0592Mhz的晶振。
6〖文件〗 PCF8563T.C 2001/11/2 7
7
〖作者〗龙啸九天 /
8
〖修改〗修改
9
〖版本〗 V1.00A Build 0803
10 —————————————————————*/
11
12 #ifndef SDA
13 #define SDA P0_0
14 #define SCL P0_1
15 #endif
16
17 extern uchar SystemError;
18
19 #define uchar unsigned char
20 #define uint unsigned int
21 #define Byte unsigned char
22 #define Word unsigned int
23 #define bool bit
24 #define true 1
25 #define false 0
26
27 #define SomeNOP(); _nop_();_nop_();_nop_();_nop_();
28
29 /**--------------------------------------------------------------------------------
30
调用方式: void I2CStart(void) 2001/07/0 4
31
函数说明:私有函数, I2C专用
32 ---------------------------------------------------------------------------------*/
33 void I2CStart(void)
34 {
35 EA=0;
36 SDA=1; SCL=1; SomeNOP();//INI
37 SDA=0; SomeNOP(); //START
38 SCL=0;
39 }
40
41 /**--------------------------------------------------------------------------------
42
调用方式: void I2CStop(void) 2001/07/0 4
43
函数说明:私有函数, I2C专用
44 ---------------------------------------------------------------------------------*/
45 void I2CStop(void)
46 {
47 SCL=0; SDA=0; SomeNOP(); //INI
48 SCL=1; SomeNOP(); SDA=1; //STOP
49 EA=1;
50 }
51
52 /**--------------------------------------------------------------------------------
53
调用方式: bit I2CAck(void) 2001/07/0 4
54
函数说明:私有函数, I2C专用,等待从器件接收方的应答
55 ---------------------------------------------------------------------------------*/
56 bool WaitAck(void)
57 {
58 uchar errtime=255;//
因故障接收方无 ACK,超时值为 255
59 SDA=1;SomeNOP();
60 SCL=1;SomeNOP();
61 while(SDA) {errtime--; if (!errtime) {I2CStop();SystemError=0x11;return false;}}
62 SCL=0;
63 return true;


评论

技术专区