📄 24c64.lst
字号:
C51 COMPILER V7.09 24C64 11/16/2008 20:51:23 PAGE 1
C51 COMPILER V7.09, COMPILATION OF MODULE 24C64
OBJECT MODULE PLACED IN 24C64.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24C64.c BROWSE DEBUG OBJECTEXTEND
line level source
1 //--------------------------
2 #include<reg51.h>
3 #include<intrins.h>
4 #include<absacc.h>
5 //-------------------------
6 #define uchar unsigned char
7 #define uint unsigned int
8 //----------------------------
9 //----------------------------
10 sbit I2cSDA_24C64=P0^5;
11 sbit I2cSCL_24C64=P0^4;
12 ///*************************************************
13 //延时子程序
14 //**************************************************/
15 void DelayX1m(uint count)
16 {
17 1 uint i;
18 1 uchar j;
19 1 for(i=0;i<count;i++)
20 1 for(j=0;j<120;j++);
21 1 }
22 /**************************************************/
23 void I2cWait_24C64(void)
24 {
25 1 _nop_();
26 1 _nop_();
27 1 }
28 ///*************************************************
29 //初始化
30 //**************************************************/
31 void I2cInit_24C64(void)
32 {
33 1 I2cSDA_24C64=1;
34 1 I2cSCL_24C64=1;
35 1 }
36 ///*******************************************
37 //启动器件子程序
38 //*******************************************/
39 void I2cStar_24C64(void)
40 {
41 1 I2cSDA_24C64=1;
42 1 I2cSCL_24C64=1;
43 1 I2cWait_24C64();
44 1 I2cSDA_24C64=0;
45 1 I2cWait_24C64();
46 1 I2cSCL_24C64=0;
47 1 }
48 ///*******************************************
49 //器件停止子程序
50 //*******************************************/
51 void I2cStop_24C64(void)
52 {
53 1 I2cSDA_24C64=0;
54 1 I2cWait_24C64();
55 1 I2cSCL_24C64=1;
C51 COMPILER V7.09 24C64 11/16/2008 20:51:23 PAGE 2
56 1 I2cWait_24C64();
57 1 I2cSDA_24C64=1;
58 1 }
59 ///*******************************************
60 //主机发送一个字节数据至24C02子程序
61 //*******************************************/
62 bit I2cSentByte_24C64(char bytedata)
63 {
64 1
65 1 uchar i;
66 1 bit ack;
67 1 for(i=0;i<8;i++)
68 1 {
69 2 if(bytedata & 0x80)
70 2 I2cSDA_24C64=1;
71 2 else
72 2 I2cSDA_24C64=0;
73 2 bytedata<<=1;
74 2 I2cWait_24C64();
75 2 I2cSCL_24C64=1;
76 2 I2cWait_24C64();
77 2 I2cSCL_24C64=0;
78 2 I2cWait_24C64();
79 2 }
80 1 I2cSDA_24C64=1;
81 1 I2cWait_24C64();
82 1 I2cSCL_24C64=1;
83 1 I2cWait_24C64();
84 1 ack=I2cSDA_24C64;//从24C16中读取SDA的状态
85 1 I2cSCL_24C64=0;
86 1 I2cWait_24C64();
87 1 return ack;
88 1 }
89 ///**************************************************
90 //主机接收一个字节数据子程序
91 //***************************************************/
92 uchar I2cReceiveByte_24C64(void)
93 {
94 1 char i,bytedata=0;
95 1 for(i=0;i<8;i++)
96 1 {
97 2 I2cSCL_24C64=1;
98 2 I2cWait_24C64();
99 2 bytedata<<=1;
100 2 if(I2cSDA_24C64)bytedata |= 0x01;
101 2 I2cSCL_24C64=0;
102 2 I2cWait_24C64();
103 2 }
104 1 return bytedata;
105 1 }
106 ///*************************************************
107 //传送确认信号“1”或“0”电平到s
108 //**************************************************/
109 void SendAcknowledge_24C64(bit ack)
110 {
111 1 I2cSDA_24C64=ack;
112 1 I2cSCL_24C64=1;
113 1 I2cWait_24C64();
114 1 I2cSCL_24C64=0;
115 1 }
116 ///*************************************************
117 //将数据写入指定24C64地址内
C51 COMPILER V7.09 24C64 11/16/2008 20:51:23 PAGE 3
118 //**************************************************/
119 void I2cByteWrite_24C64(uchar device,uchar firstaddress,uchar bytedata)
120 {
121 1 uchar i;
122 1 bit ack,FgTimeout=1;
123 1 for(i=0;i<10;i++)
124 1 {
125 2 I2cStar_24C64();
126 2 ack=I2cSentByte_24C64(device);
127 2 if(ack==1)
128 2 {
129 3 I2cStop_24C64();
130 3 continue;
131 3 }
132 2 ack=I2cSentByte_24C64(firstaddress);
133 2 if(ack==1)
134 2 {
135 3 I2cStop_24C64();
136 3 continue;
137 3 }
138 2 // ack=I2cSentByte_24C64(secondaddress);
139 2 if(ack==1)
140 2 {
141 3 I2cStop_24C64();
142 3 continue;
143 3 }
144 2 ack=I2cSentByte_24C64(bytedata);
145 2 if(ack==1)
146 2 {
147 3 I2cStop_24C64();
148 3 continue;
149 3 }
150 2 I2cStop_24C64();
151 2 FgTimeout=0;
152 2 if(ack==0) break;
153 2 }
154 1 DelayX1m(10);
155 1 }
156 //**************************************************
157 //连续写几个数据
158 //***************************************************
159 //void I2cByteWrite_ndata_24C64(uchar device,uchar firstaddress,uchar *bytedata,uchar n)
160 //{
161 // for(;n>0;n--)
162 // {
163 // I2cByteWrite_24C64( device, firstaddress, *bytedata);
164 // firstaddress++;
165 // bytedata++;
166 // }
167 //}
168 //****************************************************
169 //*************************************************
170 //将数据从指定24C64地址内读出
171 //**************************************************/
172 uchar I2cByteRead_24C64(uchar device,uchar firstaddress)//Random Read 随机读取,不是正规的读取
173 {
174 1 uchar bytedata;
175 1 I2cStar_24C64();
176 1 I2cSentByte_24C64(device);
177 1 I2cSentByte_24C64(firstaddress);//上面是发出一个写的模式
178 1 // I2cSentByte_24C64(secondaddress);
179 1 I2cStar_24C64();
C51 COMPILER V7.09 24C64 11/16/2008 20:51:23 PAGE 4
180 1 I2cSentByte_24C64(device|0x01);//发出读的信号
181 1 bytedata=I2cReceiveByte_24C64();
182 1 SendAcknowledge_24C64(1);
183 1 I2cStop_24C64();
184 1 return bytedata;
185 1 }//=============================================================================
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 252 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = ---- ----
BIT SIZE = ---- 4
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -