⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.lst

📁 该程序利用单片机完成数据在串口与SMBus总线(即I2C)之间的转发
💻 LST
📖 第 1 页 / 共 2 页
字号:
 238   4                                      IIC_Busy=1;
 239   4                              //      while(IIC_Busy==1);
 240   4      
 241   4                              }
C51 COMPILER V7.06   MAIN                                                                  12/04/2006 10:14:46 PAGE 5   

 242   3      
 243   3      
 244   3                      }
 245   2                      if(RxFlag==1)
 246   2                      {
 247   3                              RxFlag=0;
 248   3                              SBUF0=RxData;
 249   3                              while(UART_Tx_Complete == 0);
 250   3                              UART_Tx_Complete = 0;
 251   3      
 252   3                      }
 253   2                      
 254   2              }       
 255   1              
 256   1      }
 257          /*SMBus中断处理程序*/
 258          void SMBus_Interrupt(void) interrupt 7
 259          {
 260   1      
 261   1         bit FAIL;                                 // Used by the ISR to flag failed
 262   1                                                   // transfers
 263   1         static bit ADDR_SEND;                     // Used by the ISR to flag byte
 264   1                                                   // transmissions as slave addresses
 265   1      
 266   1         switch (SMB0CN & 0xF0)                    // Status vector
 267   1         {
 268   2            // Master Transmitter/Receiver: START condition transmitted.
 269   2            case SMB_MTSTA:
 270   2               //SMB0DAT = TARGET;                   // Load address of the target slave
 271   2               //SMB0DAT |= SMB_RW;                  // Load R/W bit
 272   2               //STA = 0;                            // Manually clear START bit
 273   2                       SMB0DAT =RWByte;//UartFrame[1] ;       //发出从器件XFP地址以及R/W位
 274   2                       //SBUF0=UartFrame[1];
 275   2                       //while(UART_Tx_Complete == 0);
 276   2                       //UART_Tx_Complete = 0;        
 277   2                       STA = 0;
 278   2                       i=1;
 279   2               ADDR_SEND = 1;
 280   2                       break;
 281   2      
 282   2            // Master Transmitter: Data byte transmitted
 283   2            case SMB_MTDB:
 284   2               if (ACK)                            // Slave ACK?
 285   2               {
 286   3                              //if(UartFrame[1]==0xA1)        //此次是读操作里面的写地址
 287   3                      //      {
 288   3                      //              SMB0DAT =UartFrame[2] ; //读Rom的地址
 289   3                      //              StopRequire=1;
 290   3                              //      STO=1;          //写地址完毕
 291   3                      //      //      IIC_Busy=0;
 292   3                      //      }
 293   3      
 294   3                              //else          //是写操作
 295   3                              //{
 296   3      
 297   3                                      i++;
 298   3                              if(RWByte==0xA0)//WRITE 
 299   3                              {
 300   4                                      if(((UartFrame[i]=='P')&&(i==UartFrame_Num))||(StopRequire==1))//stop
 301   4                                      {
 302   5                                              STO=1;  //停止命令
 303   5                                      //      pRomAddr=pRomAddr+i-3;
C51 COMPILER V7.06   MAIN                                                                  12/04/2006 10:14:46 PAGE 6   

 304   5                                              IIC_Busy=0;
 305   5                                              StopRequire=0;
 306   5                                      }
 307   4                                      else                                                                    //send
 308   4                                      {
 309   5                                              SMB0DAT =UartFrame[i] ; //写Prom的地址或数据,发送
 310   5                                              if(UartFrame[1]==0xA1)  //此次是读操作里面的写地址
 311   5                                                      StopRequire=1;
 312   5                                              
 313   5                                              ////SBUF0=UartFrame[1];
 314   5                                              //while(UART_Tx_Complete == 0);
 315   5                                              // UART_Tx_Complete = 0;        
 316   5                                      }
 317   4                               }
 318   3                               else{}         //do nothing
 319   3                               
 320   3                               //}
 321   3               /*
 322   3                              if (ADDR_SEND)                   // If the previous byte was a slave
 323   3                  {                                // address,
 324   3                                      ADDR_SEND = 0;                // Next byte is not a slave address
 325   3                     if (SMB_RW==WRITE)            // If this transfer is a WRITE,
 326   3                     {
 327   3                        SMB0DAT = SMB_DATA_OUT;    // send data byte
 328   3                     }
 329   3                     else {}                       // If this transfer is a READ,
 330   3                                                   // proceed with transfer without
 331   3                                                   // writing to SMB0DAT (switch
 332   3                                                   // to receive mode)
 333   3                  }
 334   3                  else                             // If previous byte was not a slave
 335   3                  {                                // address,
 336   3                     STO = 1;                      // set STO to terminte transfer
 337   3                     SMB_BUSY = 0;                 // and free SMBus interface
 338   3                  }*/
 339   3               }
 340   2               else                                // If slave NACK,
 341   2               {
 342   3                  FAIL = 1;                        // Indicate failed transfer
 343   3                                                   // and handle at end of ISR
 344   3               }
 345   2               break;
 346   2      
 347   2            // Master Receiver: byte received
 348   2            case SMB_MRDB:
 349   2                      //      UartTxFrame[i+1] =SMB0DAT;      //发出从器件地址以及R/W位
 350   2                              RxData=SMB0DAT; 
 351   2                              RxFlag=1;
 352   2                      //      UartTxFrame[i]=pRomAddr;
 353   2                              pRomAddr++;
 354   2                              I2CRxNum--;
 355   2                              if((I2CRxNum!=0)&&(pRomAddr!=256))              //读页数据
 356   2                              //if((UartFrame[3]==0xFF)&&(pRomAddr!=256))             //读页数据
 357   2                              {
 358   3                                      ACK=1;
 359   3                                      i=i+2;
 360   3                              }
 361   2                              else
 362   2                              {
 363   3                                      ACK=0;          //给出传送完毕信息
 364   3                                      //i=0;
 365   3                                      STO=1;          //停止
C51 COMPILER V7.06   MAIN                                                                  12/04/2006 10:14:46 PAGE 7   

 366   3                                      IIC_Busy=0;
 367   3                              }
 368   2            
 369   2                       //SMB_DATA_IN = SMB0DAT;              // Store received byte
 370   2               //SMB_BUSY = 0;                       // Free SMBus interface
 371   2               //ACK = 0;                            // Send NACK to indicate last byte
 372   2                                                   // of this transfer
 373   2      
 374   2               //STO = 1;                            // Send STOP to terminate transfer
 375   2               break;
 376   2      
 377   2            default:
 378   2               FAIL = 1;                           // Indicate failed transfer
 379   2                                                   // and handle at end of ISR
 380   2               break;
 381   2         
 382   2         } // end switch
 383   1      
 384   1         if (FAIL)                                 // If the transfer failed,
 385   1         {
 386   2            SMB0CN &= ~0x40;                       // Reset communication
 387   2            SMB0CN |= 0x40;
 388   2            SMB_BUSY = 0;                          // Free SMBus
 389   2         }
 390   1      
 391   1         SI=0;                                     // clear interrupt flag
 392   1      
 393   1      }
 394          /*UART中断处理程序*/
 395          void UART_Interrupt(void) interrupt 4
 396          {
 397   1      
 398   1      /*如果串口接收到一个字节,将其写入串口缓冲区*/
 399   1              if(RI0)
 400   1              {
 401   2      //              LED=!LED;
 402   2                      temp=SBUF0;
 403   2                      t++;
 404   2      //              SBUF0=UartFrame[i];
 405   2      //              while(UART_Tx_Complete == 0);
 406   2      //              UART_Tx_Complete = 0;   
 407   2      
 408   2                      if((temp=='S')&&(temp_last=='P'))       //起始
 409   2                      {
 410   3                              num=0;
 411   3                              UartFrame[0]=temp;
 412   3                      }
 413   2                      else if(UartFrame[0]=='S')
 414   2                              UartFrame[num]=temp;
 415   2      
 416   2                      if((temp=='P')&&(UartFrame[0]=='S'))
 417   2                      {
 418   3              //              if(((UartFrame[1]==0xA0)&&(UartFrame[3]==num))||(UartFrame[1]==0xA1))//写操作需要长度信息。
 419   3                              {
 420   4      //                              UartFrame_Complete=1;
 421   4                                      
 422   4                                      if((num+1)>=5)  //必须大于5个数据才算一组帧
 423   4                                      {
 424   5                                              UartFrame_Complete=1;
 425   5                                              UartFrame_Num=num;//UartFrame_Num是这个包的数据个数
 426   5                                              
 427   5                                      }
C51 COMPILER V7.06   MAIN                                                                  12/04/2006 10:14:46 PAGE 8   

 428   4                                      //else  UartFrame[num]=temp;            
 429   4                              }
 430   3      
 431   3                      }
 432   2                      num++;
 433   2      
 434   2                      temp_last=temp;
 435   2                              
 436   2              RI0=0;
 437   2      
 438   2              }
 439   1              /*如果串口发送完一个字节,将UART_Tx_Complete置1*/
 440   1              else if(TI0)
 441   1              {
 442   2                      
 443   2                      UART_Tx_Complete = 1;
 444   2                      TI0 = 0;
 445   2              }
 446   1      }
 447          
 448          
 449          /*SMBus发送字节程序*/
 450          void SMBus_Tx(unsigned char ch)
 451          {
 452   1              while(SMB0CF & 0x20 != 0);//查询SMBus总线是否BUSY
 453   1              SMBus_Txchar = ch;
 454   1              SMBus_TxCount = 1;
 455   1              STA = 1;
 456   1      }
 457          /*读缓冲区程序*/
 458          unsigned char ReadBuffer(unsigned char* Buffer,unsigned char* pFront,unsigned char* pRear)
 459          {
 460   1              unsigned char ch;
 461   1              *pFront = ((*pFront)+1) % MAXBUFSIZE;
 462   1              ch = Buffer[*pFront];
 463   1              return ch;
 464   1      }
*** WARNING C280 IN LINE 458 OF MAIN.C: 'pRear': unreferenced local variable
 465          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    628    ----
   CONSTANT SIZE    =   ----    ----
   XDATA SIZE       =    400    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     28       9
   IDATA SIZE       =   ----    ----
   BIT SIZE         =      5       1
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  1 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -