📄 24c01.lst
字号:
C51 COMPILER V7.50 24C01 07/27/2007 22:36:44 PAGE 1
C51 COMPILER V7.50, COMPILATION OF MODULE 24C01
OBJECT MODULE PLACED IN 24C01.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE 24C01.C BROWSE DEBUG OBJECTEXTEND
line level source
1 //#pragma ot(6,SIZE)
2 #include "24CXX.h"
3 //enum eepromtype {M2401,M2402,M2404,DS1307,M2408,M2416,M2432,M2464,M24128,M24256};
4 //enum eepromtype EepromType;
5 //#include <reg52.h>
6 #include <intrins.h>
7 //DataBuff为读写数据输入/输出缓冲区的首址
8 //ByteQuantity 为要读写数据的字节数量
9 //Address 为EEPROM的片内地址
10 //ControlByte 为EEPROM的控制字节
11 //具体形式为(1)(0)(1)(0)(A2)(A1)(A0)(R/W),其中R/W=1,
12 //表示读操作,R/W=0为写操作,A2,A1,A0为EEPROM的页选或片选地址;
13 //EepromType为枚举变量,需为M2401至M24256中的一种,分别对应24C01至24C256;
14 //函数返回值为一个位变量,若返回1表示此次操作失效,0表示操作成功;
15 //ERRORCOUNT为允许最大次数,若出现ERRORCOUNT次操作失效后,则函数中止操作,并返回1
16 //SDA和SCL由用户自定义,这里暂定义为P0^0和P0^1;
17 //其余的用户不用管,只要把只子程序放在你的程序中并调用它就可以了;
18
19
20 bit RW24XX(unsigned char *DataBuff,unsigned char ByteQuantity,unsigned int Address,
21 unsigned char ControlByte,enum eepromtype EepromType)
22 {
23 1 unsigned char data j,i=ERRORCOUNT;
24 1 bit errorflag=1;
25 1 while(i--)
26 1 {
27 2 IICStart();
28 2 IICSendByte(ControlByte&0xfe);
29 2 if(IICRecAck())
30 2 continue;
31 2 if(EepromType>M2416)
32 2 {
33 3 IICSendByte((unsigned char)(Address>>8));
34 3 if(IICRecAck())
35 3 continue;
36 3 }
37 2 IICSendByte((unsigned char)Address);
38 2 if(IICRecAck())
39 2 continue;
40 2 if(!(ControlByte&0x01))
41 2 {
42 3 j=ByteQuantity;
43 3 errorflag=0; //********clr errorflag
44 3 while(j--)
45 3 {
46 4 IICSendByte(*DataBuff++);
47 4 if(!IICRecAck())
48 4 continue;
49 4 errorflag=1;
50 4 break;
51 4 }
52 3 if(errorflag==1)
53 3 continue;
54 3 break;
55 3 }
C51 COMPILER V7.50 24C01 07/27/2007 22:36:44 PAGE 2
56 2 else
57 2 {
58 3 IICStart();
59 3 IICSendByte(ControlByte);
60 3 if(IICRecAck())
61 3 continue;
62 3 while(--ByteQuantity)
63 3 {
64 4 *DataBuff++=IICReceiveByte();
65 4 IICAck();
66 4 }
67 3 *DataBuff=IICReceiveByte(); //read last byte data
68 3 IICNoAck();
69 3 errorflag=0;
70 3 break;
71 3 }
72 2 }
73 1 IICStop();
74 1 if(!(ControlByte&0x01))
75 1 {
76 2 Delay(255);
77 2 Delay(255);
78 2 Delay(255);
79 2 Delay(255);
80 2 }
81 1 return(errorflag);
82 1 }
83
84 unsigned char RDIIC(unsigned char *DataBuff,unsigned char ByteQuantity,unsigned int Address,
85 unsigned char chipadd,enum eepromtype EepromType)
86 {
87 1 // unsigned char data j;//,i=ERRORCOUNT;
88 1 unsigned char temp;
89 1 // bit errorflag=1;
90 1 temp=((Address&0x7ff)/256)<<1;
91 1 IICStart();
92 1 IICSendByte(chipadd|temp);
93 1 IICRecAck();
94 1 if(EepromType>M2416)
95 1 {
96 2 IICSendByte((unsigned char)(Address>>8));
97 2 IICRecAck();
98 2 }
99 1 IICSendByte((unsigned char)Address);
100 1 IICRecAck();
101 1
102 1 IICStart();
103 1 IICSendByte(chipadd|temp|0x01);
104 1 IICRecAck();
105 1 while(--ByteQuantity)
106 1 {
107 2 *DataBuff++=IICReceiveByte();
108 2 IICAck();
109 2 }
110 1 *DataBuff=IICReceiveByte(); //read last byte data
111 1 IICNoAck();
112 1 IICStop();
113 1 return(temp);
114 1 }
115 unsigned char WDIIC(unsigned char *DataBuff,unsigned char ByteQuantity,unsigned int Address,
116 unsigned char chipadd,enum eepromtype EepromType)
117 {
C51 COMPILER V7.50 24C01 07/27/2007 22:36:44 PAGE 3
118 1 unsigned char data j,i=ERRORCOUNT;
119 1 bit errorflag=1;
120 1 unsigned char temp;
121 1
122 1 while(i--)
123 1 {
124 2 temp=((Address&0x7ff)/256)<<1;
125 2 IICStart();
126 2 IICSendByte(chipadd|temp);
127 2 if(IICRecAck())
128 2 continue;
129 2 if(EepromType>M2416)
130 2 {
131 3 IICSendByte((unsigned char)(Address>>8));
132 3 if(IICRecAck())
133 3 continue;
134 3 }
135 2 IICSendByte((unsigned char)Address);
136 2 if(IICRecAck())
137 2 continue;
138 2
139 2 j=ByteQuantity;
140 2 errorflag=0; //********clr errorflag
141 2 while(j--)
142 2 {
143 3 IICSendByte(*DataBuff++);
144 3 if(!IICRecAck())
145 3 continue;
146 3 errorflag=1;
147 3 break;
148 3 }
149 2 if(errorflag==1)
150 2 continue;
151 2 break;
152 2 }
153 1 IICStop();
154 1 Delay(100);
155 1 return(errorflag);
156 1 }
157
158
159
160 /*****************以下是对IIC总线的操作子程序***/
161 /*****************启动总线**********************/
162 void IICStart(void)
163 {
164 1 SCL=0; //
165 1 SDA=1;
166 1 SCL=1;
167 1 _nop_();
168 1 _nop_();
169 1 _nop_();
170 1 SDA=0;
171 1 _nop_();
172 1 _nop_();
173 1 _nop_();
174 1 _nop_();
175 1 SCL=0;
176 1 SDA=1; //
177 1 }
178
179 /*****************停止IIC总线****************/
C51 COMPILER V7.50 24C01 07/27/2007 22:36:44 PAGE 4
180 void IICStop(void)
181 {
182 1 SCL=0;
183 1 SDA=0;
184 1 SCL=1;
185 1 _nop_();
186 1 _nop_();
187 1 _nop_();
188 1 SDA=1;
189 1 _nop_();
190 1 _nop_();
191 1 _nop_();
192 1 SCL=0;
193 1 }
194
195 /**************检查应答位*******************/
196 bit IICRecAck(void)
197 {
198 1 SCL=0;
199 1 SDA=1;
200 1 SCL=1;
201 1 _nop_();
202 1 _nop_();
203 1 _nop_();
204 1 _nop_();
205 1 CY=SDA; //因为返回值总是放在CY中的
206 1 SCL=0;
207 1 return(CY);
208 1 }
209
210 /***************对IIC总线产生应答*******************/
211 void IICACK(void)
212 {
213 1 SDA=0;
214 1 SCL=1;
215 1 _nop_();
216 1 _nop_();
217 1 _nop_();
218 1 _nop_();
219 1 SCL=0;
220 1 _nop_();
221 1 SDA=1;
222 1 }
223
224 /*****************不对IIC总线产生应答***************/
225 void IICNoAck(void)
226 {
227 1 SDA=1;
228 1 SCL=1;
229 1 _nop_();
230 1 _nop_();
231 1 _nop_();
232 1 _nop_();
233 1 SCL=0;
234 1 }
235
236 /*******************向IIC总线写数据*********************/
237 void IICSendByte(unsigned char sendbyte)
238 {
239 1 unsigned char data j=8;
240 1 for(;j>0;j--)
241 1 {
C51 COMPILER V7.50 24C01 07/27/2007 22:36:44 PAGE 5
242 2 SCL=0;
243 2 sendbyte<<=1; //无论C51怎样实现这个操作,始终会使CY=sendbyte^7;
244 2 SDA=CY;
245 2 SCL=1;
246 2 }
247 1 SCL=0;
248 1 }
249
250 /**********************从IIC总线上读数据子程序**********/
251 unsigned char IICReceiveByte(void)
252 {
253 1 register receivebyte,i=8;
254 1 SCL=0;
255 1 while(i--)
256 1 {
257 2 SCL=1;
258 2 receivebyte=(receivebyte<<1)|SDA;
259 2 SCL=0;
260 2 }
261 1 return(receivebyte);
262 1 }
263
264 /***************一个简单延时程序************************/
265
266 void Delay(unsigned char DelayCount)
267 {
268 1 while(DelayCount--);
269 1 }
270
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 612 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 32
IDATA SIZE = ---- ----
BIT SIZE = ---- 2
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -