📄 func_shi.lst
字号:
271 1 _nop_ ();
272 1 delay_nop();
273 1 scl = 0; // scl low
274 1 delay_nop();
275 1 sda = 1; // sda high
276 1 delay_nop();
277 1 }
278
279 /*********************************************************************
280 Not Acknowledge Function
281 *********************************************************************/
282 void nack_con()
283 {
284 1 // Acknowledge active
285 1 sda = 0; // sda low
286 1 delay_nop();
287 1 scl = 1; // scl high
288 1 delay_nop();
289 1 //Stop active
290 1 sda = 1; // sda high
291 1 delay_nop();
292 1 scl = 0; // scl low
293 1 delay_nop();
294 1 }
295 /*********************************************************************
296 Start Function
297 *********************************************************************/
298 void start_con()
299 {
300 1 sda = 1; // sda high
301 1 delay_nop();
302 1 scl = 1; // scl high
C51 COMPILER V7.50 FUNC_SHI 01/14/2006 15:30:02 PAGE 6
303 1 delay_nop();
304 1 //if(scl&sda){printf("this is stop ");};
305 1 sda = 0; // sda low
306 1 delay_nop();
307 1 // if(scl&!sda){printf("this is stop 0");};
308 1 scl = 0; // scl low
309 1 delay_nop();
310 1 }
311
312 /*********************************************************************
313 Stop Function
314 *********************************************************************/
315 void stop_con()
316 {
317 1 bit end = 0; // A Flag => 0:Repeat stop motion
318 1 // 1:Complete stop motion
319 1 while (end == 0)
320 1 {
321 2 scl = 0; // scl low
322 2 delay_nop();
323 2 sda = 0; // sda low
324 2 delay_nop();
325 2 // if(!scl&!sda){printf("this is stop 0");};
326 2 scl = 1; // scl high
327 2 delay_nop();
328 2 sda = 1; // sda high
329 2 delay_nop();
330 2 // if(scl&sda){printf("this is stop 1");};
331 2 if (sda == 1) // Check the device response
332 2 {
333 3 end = 1; // Set "Complete" Flag
334 3 }
335 2 }
336 1 }
337
338 /*********************************************************************
339 Delay Function
340 Machine cycle = 24x2 + 12x3 = 84
341 Crystal Frequency = 20 MHz
342 Delay Time: 4.2us
343 *********************************************************************/
344 void delay_nop()
345 {
346 1 _nop_ ();
347 1 _nop_ ();
348 1 _nop_ ();
349 1 }
350 /********************************************************************
351 Delay x ms Function
352 Crystal Frequency = 20 MHz
353 Delay Time: count x 1ms
354 ********************************************************************/
355 void DelayXms(unsigned char count)
356 {
357 1 unsigned char data i,j;
358 1 for (i = 0;i < count;i++)
359 1 {
360 2 for (j = 0;j < 0xc8;j++)
361 2 {
362 3 _nop_();
363 3 }
364 2 }
C51 COMPILER V7.50 FUNC_SHI 01/14/2006 15:30:02 PAGE 7
365 1 }
366
367 void shi_sub_read1(char device,char num_data,char *buf_data)
368 {
369 1 unsigned char data count = 0;
370 1 char *buf_data_temp;
371 1 bit EA_temp;
372 1 bit com = 0; // A flag to indicate whether the read motion is complete
373 1 // com = 0 => Not complete
374 1 // com = 1 => Complete
375 1 EA_temp=EA;
376 1 EA=0;
377 1
378 1 com = 0;
379 1
380 1 buf_data_temp = buf_data;
381 1 stop_con(); // Master send Stop command
382 1
383 1 delay_nop();
384 1 start_con(); // Master send Start command
385 1
386 1
387 1 ack = send_con(++device); // Send the device number and Set the R/W bit
388 1
389 1 {
390 2
391 2 for (count = 0;count <= num_data;count++)
392 2 {
393 3 *buf_data_temp = receive_con1(); // Save received data to buf_data
-
394 3 buf_data_temp++; // Address index increase
395 3 if (count != num_data) // Check whether the data is the last
396 3 {
397 4 ack_con();
398 4 }
399 3 else
400 3 {
401 4 nack_con();
402 4 com = 0; //printf("com=0\n");
403 4 goto Com_Received;
404 4 }
405 3 }
406 2 }
407 1 //}*/
408 1 Com_Received:
409 1 delay_nop();
410 1 stop_con();
411 1 delay_nop();
412 1
413 1 EA=EA_temp;
414 1
415 1 }
416
417
418 /********************************************************
419
420
421
422 s-35390Atimer.by zld.2005.12
423
424 ********************************************************/
425 void shi_sub_write1(char device,unsigned char num_data,char *buf_data)
C51 COMPILER V7.50 FUNC_SHI 01/14/2006 15:30:02 PAGE 8
426 {
427 1 bit com = 0;
428 1 unsigned char data count = 0;
429 1 char *buf_data_temp1;
430 1 bit EA_temp;
431 1 EA_temp=EA;
432 1 EA=0;
433 1 _nop_();
434 1
435 1 while (!com)
436 1 {
437 2 buf_data_temp1 = buf_data;
438 2 stop_con(); // Master send Stop command
439 2 delay_nop();
440 2 start_con(); // Master send Start command
441 2 ack = send_con(device); // Send the device number and Set the R/W bit
442 2
443 2 for (count=0;count <= num_data;count++)
444 2 {
445 3 if (!ack)
446 3 {
447 4 ack = send_con1(*buf_data_temp1); // Send the data pointed the buf_data index
448 4 buf_data_temp1++; // Address index increase
449 4 if (count == num_data && !ack )
450 4 {
451 5 com = 1;
452 5 //printf("com=1 exec\n");
453 5 break;
454 5 }
455 4 }
456 3 else
457 3 {
458 4 break;
459 4 }
460 3 }
461 2
462 2 }
463 1 delay_nop();
464 1 stop_con(); // Master send Stop command
465 1 delay_nop();
466 1
467 1 EA=EA_temp;
468 1 }
469
470
471 char receive_con1()
472 {
473 1 char count = 0;
474 1 unsigned char byte=0;
475 1
476 1 for (count=0;count<8;count++)
477 1 {
478 2 // printf("receive=%bx\n",byte);
479 2 byte>>= 1;
480 2 scl = 1; // scl high
481 2 delay_nop();
482 2 if (sda)
483 2 {
484 3 byte|= 0x80;
485 3 }
486 2 scl = 0; // scl low
487 2 delay_nop();
C51 COMPILER V7.50 FUNC_SHI 01/14/2006 15:30:02 PAGE 9
488 2 }
489 1 return (byte);
490 1 }
491
492 bit send_con1(char bytedata)
493 {
494 1 char data count = 0;
495 1
496 1 scl = 0;
497 1 delay_nop();
498 1 for (count=0;count<8;count++)
499 1 {
500 2 //sda = 0; // sda low
501 2 if (bytedata & 0x01)
502 2 sda = 1; // sda high
503 2 else
504 2 sda = 0;
505 2 delay_nop();
506 2 bytedata >>= 1; // bytedata left shift
507 2 //printf("bytedata=%bx",bytedata);
508 2
509 2 // Generate SCLK
510 2 scl = 1; // scl high
511 2 //_nop_ ();
512 2 delay_nop();
513 2 scl = 0; // scl low
514 2 delay_nop();
515 2 }
516 1 //delay_nop(); //CSWU2005.11.6
517 1
518 1 // Readback ack
519 1 sda = 1; // sda high //CSWU2005.11.15 1->0
520 1 delay_nop();
521 1 scl = 1; // scl high
522 1 delay_nop();
523 1 //delay_nop();
524 1 //delay_nop();
525 1 ack = sda; // Read ack
526 1 // Ack = 0 => Acknowledge
527 1 // Ack = 1 => No Acknowledge
528 1 delay_nop();
529 1 scl = 0; // scl low
530 1 delay_nop();
531 1 return (ack);
532 1 }
533
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 976 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 1 33
PDATA SIZE = ---- ----
DATA SIZE = ---- 8
IDATA SIZE = ---- ----
BIT SIZE = 1 9
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -