📄 isr_i2c.lst
字号:
390 void I2CTxClearSCL (I2Cdesc *I2C_pt)
391 //* Begin
392 {
393 1 //* Clear SCL line
394 1
395 1 SCL_CLR();
396 1
397 1 if(I2C_pt->countBit == 0)
398 1 //* set SDA line as an input
399 1
400 1 //* change interrupt handler to I2CTxSendBit
401 1 I2C_pt->I2CTCHandler = I2CTxSendBit;
402 1
403 1 //* End
404 1 }
405
406
407 //*-----------------------------------------------------------------------------
408 //* 函数名称 : I2CRxSetSCL (I2Cdesc *I2C_pt)
409 //* Object : I2C
410 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
411 //* 输出变量 : 无
412 //* 功能 :为在接收数据时把SCL线设置为高电平
413 //*-----------------------------------------------------------------------------
414 void I2CRxSetSCL (I2Cdesc *I2C_pt)
415 //* Begin
416 {
417 1 //* set SCL line
418 1 SCL_SET();
419 1
420 1 //* change interrupt handler to I2CRxReceiveBit
421 1 I2C_pt->I2CTCHandler = I2CRxReceiveBit;
422 1
423 1 //* End
424 1 }
425
426
427 //*-----------------------------------------------------------------------------
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 8
428 //* 函数名称 : I2CRxClearSCL (I2Cdesc *I2C_pt)
429 //* Object : I2C
430 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
431 //* 输出变量 : 无
432 //* 功能 :为在接收数据时把SCL线设置为低电平
433 //*-----------------------------------------------------------------------------
434 void I2CRxClearSCL (I2Cdesc *I2C_pt)
435 //* Begin
436 {
437 1 //* Clear SCL line
438 1 SCL_CLR();
439 1
440 1 if(I2C_pt->countBit == 0)
441 1 {
442 2 //* change interrupt handler to I2CI2CRxPrepareACK
443 2 I2C_pt->I2CTCHandler = I2CRxPrepareACK;
444 2
445 2 //* set SDA line as an output
446 2
447 2 //* clear SDA line
448 2 SDA_CLR();
449 2 }
450 1 else
451 1 //* change interrupt handler to I2CRx
452 1 I2C_pt->I2CTCHandler = I2CRxReceiveBit;
453 1
454 1 //* End
455 1 }
456
457
458 //*-----------------------------------------------------------------------------
459 //* 函数名称 : I2CRxReceiveByte (I2Cdesc *I2C_pt)
460 //* Object : I2C
461 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
462 //* 输出变量 : 无
463 //* 功能 :为在从I2C中接收一个字节的数据
464 //*-----------------------------------------------------------------------------
465 unsigned int ttmp=0;
466 void I2CRxReceiveByte (I2Cdesc *I2C_pt)
467 //* Begin
468 {
469 1 //* set SDA line as an input
470 1 //* clear SCL line
471 1 SCL_CLR();
472 1
473 1 //* initialize countBit
474 1 I2C_pt->countBit = 8;
475 1 *I2C_pt->RxEnd=0;
476 1 ttmp=0;
477 1 I2C_pt->nbI2CByte--;
478 1 if(I2C_pt->nbI2CByte == 0)
479 1 //* next mode
480 1 I2C_pt->mode = STOP;
481 1
482 1 //* change interrupt handler to I2C
483 1 I2C_pt->I2CTCHandler = I2CRxReceiveBit;
484 1
485 1 //* End
486 1 }
487
488
489 //*-----------------------------------------------------------------------------
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 9
490 //* 函数名称 : I2CRxReceiveBit (I2Cdesc *I2C_pt)
491 //* Object : I2C
492 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
493 //* 输出变量 : 无
494 //* 功能 :为在从I2C中接收一个比特的数据
495 //*-----------------------------------------------------------------------------
496 void I2CRxReceiveBit (I2Cdesc *I2C_pt)
497 //* Begin
498 {
499 1 unsigned char bit_val;
500 1
501 1 //* set SCL line
502 1 SCL_SET();
503 1
504 1 //* decrement countBit
505 1 I2C_pt->countBit--;
506 1
507 1 //* get bit
508 1 if(SDA_VAL()){
509 2 bit_val = 1;
510 2 //printk("r1 ");
511 2 }
512 1 else{
513 2 bit_val = 0;
514 2 //printk("r0 ");
515 2 }
516 1 //* if bit counter > 0
517 1 if(I2C_pt->countBit > 0){
518 2 //* update working byte
519 2 *I2C_pt->RxEnd |= (bit_val << I2C_pt->countBit);
520 2 ttmp |= (bit_val << I2C_pt->countBit);
521 2 }
522 1 else{
523 2 *(I2C_pt->RxEnd++) |= (bit_val << I2C_pt->countBit) ;
524 2 ttmp |= (bit_val << I2C_pt->countBit);
525 2 //printk("\r\n ");
526 2 }
527 1
528 1 //* change interrupt handler to I2CRxClearSCL
529 1 I2C_pt->I2CTCHandler = I2CRxClearSCL;
530 1
531 1 //* End
532 1 }
533
534
535 //*-----------------------------------------------------------------------------
536 //* 函数名称 : Timer_I2C (I2Cdesc *I2C_pt)
537 //* Object : I2C
538 //* 输入参数 : 无
539 //* 输出变量 : 无
540 //* 功能 :为I2C的中断定时器,I2C的一切函数都由此中断来驱动
541 //*-----------------------------------------------------------------------------
542 void Timer_I2C() interrupt T0_INT {//timer 1 interrupt.
543 1 if(!I2c_timer_cnt){
544 2 (*(I2c.I2CTCHandler))(&I2c); //call automate state handler
545 2 }
546 1 else{
547 2 I2c_timer_cnt--;
548 2 }
549 1 }
550
551 //*-----------------------------------------------------------------------------
C51 COMPILER V7.06 ISR_I2C 10/29/2006 14:34:14 PAGE 10
552 //* 函数名称 : I2C_lineOpen (I2Cdesc *I2C_pt, unsigned int us)
553 //* Object : I2C
554 //* 输入参数 : <I2C_pt> = 为I2C的描述指针,其结构定义在source.h中
555 //* :us 为I2C中断的时中断时间长度,此参数表示I2C的SCL的频率
556 //* 输出变量 : 无
557 //* 功能 :初始化I2C的设备和定时器
558 //*-----------------------------------------------------------------------------
559 void I2C_lineOpen (I2Cdesc *I2C_pt, unsigned int us){
560 1 /*****Set Up Paramter ***/
561 1 int tmp;
562 1 I2C_pt->deviceAddress = 0;
563 1 /*****Set Up Line****/
564 1 I2C_pt->state = OK;
565 1 SDA_SET();; //* set SDA line high
566 1 SCL_SET(); //* set SCL line high
567 1 /*****Setup Interrupt **/
568 1 /*****Setup Timer **/
569 1 I2C_pt->Timer_Gap_us=us;
570 1 Init_I2c_Timer(us);
571 1 Start_I2c_Timer(us);
572 1 }
*** WARNING C280 IN LINE 561 OF ISR_I2C.C: 'tmp': unreferenced local variable
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2287 ----
CONSTANT SIZE = ---- ----
XDATA SIZE = 30 76
PDATA SIZE = ---- ----
DATA SIZE = ---- ----
IDATA SIZE = 2 ----
BIT SIZE = ---- ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 1 WARNING(S), 0 ERROR(S)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -