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

📄 driver.lst

📁 通过遥控红外信号在电器之间传输数据的软件
💻 LST
📖 第 1 页 / 共 3 页
字号:
 226   3               NvI2c.RetryCount = 0;
 227   3               STO = 1;                
 228   3                g_bI2cError = 1;
 229   3             }
 230   2              else
 231   2              {
 232   3                 STO = 1;
 233   3                 STA = 1;
 234   3                 NvI2c.RetryCount++;
 235   3              }
 236   2              break;
 237   2              
 238   2          case 0x28://Data byte in I2DAT has been transmitted; ACK has been received
 239   2            if(bSubAddrSended)
 240   2               {
C51 COMPILER V7.50   DRIVER                                                                10/19/2006 09:37:29 PAGE 5   

 241   3                 if(NvI2c.Direction== NV_WRITE)  //write
 242   3                 {
 243   4                      if(NvI2c.DataNum--)
 244   4                      {
 245   5                       I2DAT = *(NvI2c.pbuffer++);
 246   5                       NvI2c.RetryCount = 0;
 247   5                      }
 248   4                      else
 249   4                      {
 250   5                        STO = 1;
 251   5                        g_bI2cOk = TRUE;
 252   5                      }
 253   4                 }
 254   3                 else                   //read
 255   3                 { 
 256   4                    STA = 1;     //repeated start
 257   4                    NvI2c.RetryCount = 0;
 258   4                 }
 259   3              }
 260   2              else
 261   2              {
 262   3                 I2DAT = LOWBYTE(g_wCloneNVAddress);
 263   3                 bSubAddrSended = TRUE;
 264   3              }  
 265   2      
 266   2              break;
 267   2          case 0x30://Data byte in I2DAT has been transmitted, NOT ACK has been received
 268   2            if(NvI2c.RetryCount > 3)
 269   2              {
 270   3                 NvI2c.RetryCount = 0;
 271   3                 STO = 1;
 272   3                 g_bI2cError = TRUE;
 273   3              }
 274   2              else
 275   2              {
 276   3                      I2DAT = *(NvI2c.pbuffer - 1);
 277   3                     NvI2c.RetryCount++;
 278   3              }  
 279   2              break;
 280   2          case 0x38://Arbitration lost in SLA+R/W or data bytes
 281   2            STA = 0;
 282   2            g_bI2cError = TRUE;
 283   2              break;
 284   2      
 285   2      //master receiver
 286   2              
 287   2          case 0x40://SLA+R has been transmitted; ACK has been received
 288   2            STA = 0;
 289   2            AA   = 1;
 290   2           NvI2c.RetryCount = 0;
 291   2              break;
 292   2              
 293   2          case 0x48://SLA+R has been transmitted; NOT ACK has been received
 294   2            if(NvI2c.RetryCount > 3)
 295   2              {  
 296   3              NvI2c.RetryCount = 0;
 297   3             STA = 0;
 298   3              STO = 1;
 299   3              g_bI2cError = TRUE;
 300   3              }
 301   2              else
 302   2              {
C51 COMPILER V7.50   DRIVER                                                                10/19/2006 09:37:29 PAGE 6   

 303   3               STA = 1;
 304   3               NvI2c.RetryCount++;
 305   3              }
 306   2              
 307   2              break;
 308   2              
 309   2          case 0x50://Data byte has been received; ACK has been returned
 310   2              *(NvI2c.pbuffer) =  I2DAT;
 311   2                NvI2c.pbuffer++;
 312   2                NvI2c.DataNum--;
 313   2             if(NvI2c.DataNum <= 1)   AA = 0;
 314   2              else   AA = 1;
 315   2      
 316   2                      
 317   2              break;
 318   2              
 319   2          case 0x58://Data byte has been received; NACK has been returned
 320   2            *(NvI2c.pbuffer) = I2DAT;
 321   2               STO = 1;
 322   2               g_bI2cOk = TRUE;
 323   2              break; 
 324   2              
 325   2              default:
 326   2               STA = 0;
 327   2               STO = 1;
 328   2               g_bI2cError = TRUE;
 329   2              break;  
 330   2         }
 331   1            SI = 0;
 332   1      
 333   1      }
 334          /* ======================================= */
 335          void ISR_KBI(void)  interrupt 7 using 1
 336          {
 337   1           KBCON = 0x00;//clear flag
 338   1           EKBI = 0;
 339   1           g_bKBI = TRUE;             
 340   1      }
 341          /* ======================================= */
 342          void NVWriteNByte(Byte n,Byte *pbuffer)
 343          {
 344   1         I2CStart_InterruptControl();
 345   1         NvI2c.Direction = NV_WRITE;
 346   1         NVStartTransfer(n,pbuffer);   
 347   1         I2CEnd_InterruptControl();    
 348   1      }
 349          /* ======================================= */
 350          void NVReadNByte(Byte n,Byte *pbuffer)
 351          {
 352   1         I2CStart_InterruptControl();
 353   1         NvI2c.Direction = NV_READ;
 354   1         NVStartTransfer(n,pbuffer);
 355   1         I2CEnd_InterruptControl();       
 356   1      }
 357          /* ======================================= */
 358          static void NVStartTransfer(Byte number,Byte *pbuffer)
 359          {
 360   1         NvI2c.DataNum = number;
 361   1         NvI2c.pbuffer = pbuffer;
 362   1         NvI2c.RetryCount = 0;
 363   1         bSubAddrSended = FALSE;
 364   1         g_bI2cError = FALSE;
C51 COMPILER V7.50   DRIVER                                                                10/19/2006 09:37:29 PAGE 7   

 365   1         g_bI2cOk = FALSE;
 366   1         I2CON = 0x64;// I2EN = 1;   STA = 1; AA = 1;
 367   1      }
 368          /* ======================================= */
 369          void Delay1ms(Word num)
 370          {
 371   1      /*
 372   1              TR1 = 0;
 373   1              TL1 =  LOWBYTE(ISR_TIME_1MS_RELOAD_VALUE);
 374   1              TH1 = HIGHBYTE(ISR_TIME_1MS_RELOAD_VALUE);
 375   1              TR1 = 1;
 376   1              
 377   1              ucIrSendDelayType = DELAY_1MS;
 378   1              ucDelay1msCount = num;
 379   1              while(ucDelay1msCount) ;
 380   1              TR1 = 0;
 381   1              ucIrSendDelayType = DELAY_NONE;
 382   1              */
 383   1              Byte i;
 384   1              do
 385   1              {
 386   2                      i = 200;
 387   2                      while (i--)
 388   2                              _nop_();
 389   2              }
 390   1              while (num--);
 391   1      }
 392          
 393          /* ======================================= */
 394          #ifdef DEBUG
              void IRSend_Test(void)
              {
              /*
                  IRSendLeadingCode();
                  IRSendByte(0x40);
                  IRSendByte(0xbf);      
                  IRSendByte(0x5b);
                  IRSendByte(0xa4);           
                  IRSendStop();       
                  */
               //   IRSend_SendReady();
               PIN_LED4 = 0;
               IRSendDelay(DELAY_125US);
                PIN_LED4 = 1;
               IRSendDelay(DELAY_125US);
                PIN_LED4 = 0;
               IRSendDelay(DELAY_125US);
                 PIN_LED4 = 1;
               IRSendDelay(DELAY_125US);
              }
              #endif
 416          /* ======================================= */
 417          
 418          void IRSend_SendReady(void)
 419          {
 420   1          IRSendStart_InterruptControl();
 421   1      //begin 
 422   1          IRSendLeadingCode();
 423   1          IRSendByte(0xAA);
 424   1          IRSendByte(0x55);      
 425   1          IRSendStop();       
 426   1      //end   
C51 COMPILER V7.50   DRIVER                                                                10/19/2006 09:37:29 PAGE 8   

 427   1          IRSendEnd_InterruptControl();
 428   1      }
 429          /* ======================================= */
 430          void IRSend_RecReady(void)
 431          {
 432   1          IRSendStart_InterruptControl();
 433   1      //begin 
 434   1          IRSendLeadingCode();
 435   1          IRSendByte(0xAC);
 436   1          IRSendByte(0x53);
 437   1          IRSendStop();
 438   1      //end   
 439   1          IRSendEnd_InterruptControl();
 440   1      }
 441          /* ======================================= */
 442          /*
 443          void IRSend_Address(Word address)
 444          {
 445              Byte checkSum;
 446              Byte addr[2];
 447              addr[0] = LOWBYTE(address);
 448              addr[1] = HIGHBYTE(address);        
 449              checkSum = CalculateCheckSum(2, addr);
 450              IRSendStart_InterruptControl();
 451          //begin         
 452              IRSendLeadingCode();
 453              IRSendByte(0xAB);
 454              IRSendByte(0x54); 
 455              IRSendByte(addr[1]);
 456              IRSendByte(addr[0]);
 457              IRSendByte(checkSum);
 458              IRSendStop();

⌨️ 快捷键说明

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