📄 vi2c_c51.lst
字号:
208 /*******************************************************************
209 write tx byte data function to has no sub-address device
210 original: bit ISendByte(uchar sla,ucahr c);
211 function: from start bus to tx address, data, end bus all process.
212 sla, c tx content, return 1 operate succeed.
213 note: before use must end bus.
214 ********************************************************************/
215 bit ISendByte(uchar sla,uchar c)
216 {
217 1 Start_I2c(); /*启start bus*/
218 1 SendByte(sla); /*tx device address*/
219 1 if(ack==0)return(0);
220 1 SendByte(c); /*tx data*/
221 1 if(ack==0)return(0);
222 1 Stop_I2c(); /*end bus*/
223 1 return(1);
224 1 }
225
226
227
228
229 /*******************************************************************
230 write tx data to has sub-address device function
231 original: bit ISendStr(uchar sla,uchar suba,ucahr *s,uchar no);
232 function: from start bus to tx address, data, end bus all process.
233 sla, suba, c tx content, return 1 operate succeed.
234 note: before use must end bus.
235 ********************************************************************/
236 bit ISendStr(uchar sla,uchar suba,uchar *s,uchar no)
237 {
238 1 uchar i;
239 1
240 1 Start_I2c(); /*start bus*/
241 1 SendByte(sla); /*tx device address*/
C51 COMPILER V7.50 VI2C_C51 06/01/2006 10:40:35 PAGE 5
242 1 if(ack==0)return(0);
243 1 SendByte(suba); /*tx device sub-address*/
244 1 if(ack==0)return(0);
245 1
246 1 for(i=0;i<no;i++)
247 1 {
248 2 SendByte(*s); /*tx data*/
249 2 if(ack==0)return(0);
250 2 s++;
251 2 }
252 1 Stop_I2c(); /*stop bus*/
253 1 return(1);
254 1 }
255
256
257
258
259
260
261 /*******************************************************************
262 read RX data function for has no sub-address
263 original: bit IRcvByte(uchar sla,ucahr *c);
264 功能: 从启动总线到发送地址,读数据,结束总线的全过程,从器件地
265 址sla,返回值在c.
266 如果返回1表示操作成功,否则操作有误。
267 note: before use end the bus
268 ********************************************************************/
269 bit IRcvByte(uchar sla,uchar *c)
270 {
271 1 Start_I2c(); /*启start bus*/
272 1 SendByte(sla+1); /*tx device address*/
273 1 if(ack==0)return(0);
274 1 *c=RcvByte(); /*read data*/
275 1 Ack_I2c(1); /*tx no-ack bit*/
276 1 Stop_I2c(); /*stop bus*/
277 1 return(1);
278 1 }
279
280
281
282 /*******************************************************************
283 read mult. byte data function has sub-address
284 original: bit ISendStr(uchar sla,uchar suba,ucahr *s,uchar no);
285 function: read data function
286 note: before use must end bus
287 ********************************************************************/
288 bit IRcvStr(uchar sla,uchar suba,uchar *s,uchar no)
289 {
290 1 uchar i;
291 1
292 1 Start_I2c(); /*start bus*/
293 1 SendByte(sla); /*tx device address*/
294 1 if(ack==0)return(0);
295 1 SendByte(suba); /*tx sub-address*/
296 1 if(ack==0)return(0);
297 1
298 1 Start_I2c();
299 1 SendByte(sla+1);
300 1 if(ack==0)return(0);
301 1
302 1 for(i=0;i<no-1;i++)
303 1 {
C51 COMPILER V7.50 VI2C_C51 06/01/2006 10:40:35 PAGE 6
304 2 *s=RcvByte(); /*tx data*/
305 2 Ack_I2c(0); /*tx ack bit*/
306 2 s++;
307 2 }
308 1 *s=RcvByte();
309 1 Ack_I2c(1); /*tx not ack bit*/
310 1 Stop_I2c(); /*stop bus*/
311 1 return(1);
312 1 }
313
314
315
316
317 /*******************************************************************
318 ********************************************************************
319 ********************************************************************
320 *******************************************************************/
321
322
323
324 /**********************************************************
325 write tx data to has not sub-address device function
326 original: bit ISendStr2(uchar sla,uchar *suba,ucahr *s,uchar no);
327 function: from start bus to tx address, data, end bus all process.
328 sla, suba, c tx content, return 1 operate succeed.
329 note:16 bit sub-address
330 ********************************************************************/
331 bit ISendStr2(uchar sla,uchar *suba,uchar *s,uchar no)
332 {
333 1 uchar i;
334 1 Start_I2c(); //启start bus
335 1 SendByte(sla); //tx device address
336 1 if(ack==0)return(0);
337 1 SendByte(*suba); //tx device sub-address
338 1 if(ack==0)return(0);
339 1 SendByte(*(suba+1)); //tx device sub-address
340 1 if(ack==0)return(0);
341 1
342 1 for(i=0;i<no;i++)
343 1 {
344 2 SendByte(*s); //tx data
345 2 if(ack==0)return(0);
346 2 s++;
347 2 }
348 1 Stop_I2c(); //end bus
349 1 return(1);
350 1 }
351
352
353
354
355 /*******************************************************************
356 Read rx data to has sub-address device function
357 original: bit ISendStr2(uchar sla,uchar suba,ucahr *s,uchar no);
358 function: from start bus to tx address, data, end bus all process.
359 sla, suba, c tx content, return 1 operate succeed.
360 note:16 bit sub-address
361 ********************************************************************/
362 bit IRcvStr2(uchar sla,uchar *suba,uchar *s,uchar no)
363 {
364 1 uchar i;
365 1
C51 COMPILER V7.50 VI2C_C51 06/01/2006 10:40:35 PAGE 7
366 1 Start_I2c(); //启start bus
367 1 SendByte(sla); //TX device address
368 1 if(ack==0)return(0);
369 1 SendByte(*suba); //TX device sub-address
370 1 if(ack==0)return(0);
371 1 SendByte(*(suba+1)); //TX deveice sub-address
372 1 if(ack==0)return(0);
373 1
374 1 Start_I2c();
375 1 SendByte(sla+1);
376 1 if(ack==0)return(0);
377 1
378 1 for(i=0;i<no-1;i++)
379 1 {
380 2 *s=RcvByte(); //tx data
381 2 Ack_I2c(0); //tx ack bit
382 2 s++;
383 2 }
384 1 *s=RcvByte();
385 1 Ack_I2c(1); //tx not ack bit
386 1 Stop_I2c(); //end bus
387 1 return(1);
388 1 }
389
390
391
392 /*******************************************************************
393 read mult data function for has sub address device
394 original: bit IwCheck(uchar sla)
395 function: check whether device reponse, check device write cycle
396 whether end and device whether exist.
397 ********************************************************************/
398 bit IwCheck(uchar sla)
399 {
400 1 Start_I2c(); /*启start bus*/
401 1 SendByte(sla); /*tx device address*/
402 1 if(ack==0)return(0);
403 1 Stop_I2c(); /*end bus*/
404 1 return(1);
405 1 }
406
407
408
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 863 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = ---- 43
IDATA SIZE = ---- ----
BIT SIZE = 1 1
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -