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

📄 m101(2)x_test.lst

📁 RFID source for test afl dkj
💻 LST
📖 第 1 页 / 共 2 页
字号:
 244   1      
 245   1      //增值No.5 = "2"
 246   1              cPa = ComIncrPurse5;
 247   1              Send_IIC_Command(cPa);
 248   1              cStatus = Read_Iic_Data(g_cReceBuf);
 249   1              if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
 250   1              {
 251   2                      return 8;
 252   2              }
 253   1      
 254   1      //减值 "1"
 255   1              cPa = ComDecrPurse5;
 256   1              Send_IIC_Command(cPa);
 257   1              cStatus = Read_Iic_Data(g_cReceBuf);
 258   1              if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
 259   1              {
 260   2                      return 9;
 261   2              }
 262   1      
 263   1      //restore the purse in block No.5 to block No.6
 264   1              cPa = ComBakPurse56;
 265   1              Send_IIC_Command(cPa);
 266   1              cStatus = Read_Iic_Data(g_cReceBuf);
 267   1              if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
 268   1              {
 269   2                      return 10;
 270   2              }
 271   1      
 272   1      //读最后的值No.6
 273   1              cPa = ComReadPurse6;
 274   1              Send_IIC_Command(cPa);
 275   1              cStatus = Read_Iic_Data(g_cReceBuf);
 276   1              if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
 277   1              {
 278   2                      return 11;
 279   2              }
 280   1              cPa = pursevalue;
 281   1              cPb = &g_cReceBuf[2];
 282   1              if (memcmp(cPa, cPb, 4) != 0)
 283   1              {
 284   2                      return 12;
 285   2              }
 286   1              cPa = ComHaltMCU;
 287   1              Send_IIC_Command(cPa);
 288   1              cStatus = Read_Iic_Data(g_cReceBuf);
 289   1              if ((g_cReceBuf[1] != cPa[1]) || cStatus != SUCCESS)
 290   1              {
 291   2                      return 13;
 292   2              }
 293   1              return SUCCESS;
 294   1      }
 295          
 296          /*****************************************************************************
 297          * 发光管错误指示
 298          *****************************************************************************/
 299          void ShowError(unsigned char cTimes)
 300          {
 301   1              Delay100uS(5000);
 302   1              while (cTimes--)
 303   1              {
C51 COMPILER V7.07   M101_2_X_TEST                                                         07/31/2008 19:29:08 PAGE 6   

 304   2                      LED_error = 0;
 305   2                      Delay100uS(1000);
 306   2                      LED_error = 1;
 307   2                      Delay100uS(1000);
 308   2              }
 309   1      }
 310          void delay10us()
 311          {
 312   1              unsigned char i=8;
 313   1              while(i--);
 314   1      }    
 315          /*****************************************************************************
 316          *IIC start condition
 317          *****************************************************************************/
 318          void I2CStart(void)
 319          {
 320   1              SDA = 1;delay10us();
 321   1              SCL = 1;delay10us();
 322   1              SDA = 0;delay10us();
 323   1              SCL = 0;delay10us();
 324   1      }
 325          /*****************************************************************************
 326          *IIC stop condition
 327          *****************************************************************************/
 328          void I2CStop(void)
 329          {
 330   1              SCL = 0;delay10us();
 331   1              SDA = 0;delay10us();
 332   1              SCL = 1;delay10us();
 333   1              SDA = 1;delay10us();
 334   1      }
 335          /*****************************************************************************
 336          *IIC wait ACK
 337          *****************************************************************************/
 338          bit I2CWaitAck(void)
 339          {
 340   1              unsigned int cErrTime = 755;
 341   1              SDA = 1;delay10us();
 342   1              SCL = 1;
 343   1              while(SDA)
 344   1              {
 345   2                      cErrTime--;
 346   2                      if (0 == cErrTime)
 347   2                      {
 348   3                              I2CStop();
 349   3                              return FAILURE;
 350   3                      }
 351   2              }delay10us();
 352   1              SCL = 0;delay10us();
 353   1              return SUCCESS;
 354   1      }
 355          /*****************************************************************************
 356          *IC send ACK
 357          *****************************************************************************/
 358          void I2CSendAck(void)
 359          {
 360   1              SDA = 0;delay10us();
 361   1              SCL = 1;delay10us();
 362   1              SCL = 0;delay10us();
 363   1              
 364   1      }
 365          /*****************************************************************************
C51 COMPILER V7.07   M101_2_X_TEST                                                         07/31/2008 19:29:08 PAGE 7   

 366          *IIC send Not ACK
 367          *****************************************************************************/
 368          void I2CSendNotAck(void)
 369          {
 370   1              SDA = 1;delay10us();
 371   1              SCL = 1;delay10us();
 372   1              SCL = 0;delay10us();
 373   1      }
 374          /*****************************************************************************
 375          *IIC发送一个字节
 376          *****************************************************************************/
 377          void I2CSendByte(unsigned char cSendByte)
 378          {
 379   1              unsigned char data i = 8;
 380   1              while (i--)
 381   1              {
 382   2                      SCL = 0;delay10us();
 383   2                      SDA = (bit)(cSendByte & 0x80);delay10us();
 384   2                      cSendByte += cSendByte;
 385   2                      SCL = 1;delay10us();
 386   2              }
 387   1              SCL = 0;delay10us();            
 388   1      }
 389          /*****************************************************************************
 390          接收IIC一个字节
 391          *****************************************************************************/
 392          unsigned char I2CReceiveByte(void)
 393          {
 394   1              unsigned char data i = 8;
 395   1              unsigned char data cR_Byte = 0;
 396   1              SDA = 1;delay10us();
 397   1              while (i--)
 398   1              {
 399   2                      cR_Byte += cR_Byte;
 400   2                      SCL = 0;delay10us();
 401   2                      SCL = 1;delay10us();
 402   2                      cR_Byte |= (unsigned char)SDA;delay10us();
 403   2              }
 404   1              SCL = 0;delay10us();
 405   1              return cR_Byte;
 406   1      }
 407          /*****************************************************************************
 408          读取IIC返回的数据
 409          *****************************************************************************/
 410          unsigned char Read_Iic_Data(unsigned char *cP)
 411          {
 412   1              unsigned char cCnt;
 413   1              unsigned char cCheckSum = 0;
 414   1              for (cCnt=0; cCnt<0xFF; cCnt++) 
 415   1              {
 416   2                      Delay100uS(1);
 417   2                      I2CStart();
 418   2                      I2CSendByte(READ_M101XX);
 419   2                      if (I2CWaitAck() == SUCCESS)
 420   2                      {
 421   3                              LED_UART = ~LED_UART;
 422   3                              break;
 423   3                      }
 424   2              }
 425   1              if (0xFF == cCnt)
 426   1              {
 427   2                      return FAILURE;
C51 COMPILER V7.07   M101_2_X_TEST                                                         07/31/2008 19:29:08 PAGE 8   

 428   2              }
 429   1              cP[0]=2;
 430   1              for (cCnt=0; cCnt<cP[0]; cCnt++)        // in the protocol, cP[0] is the length of this data package
 431   1              {
 432   2                      cP[cCnt] = I2CReceiveByte();
 433   2                      I2CSendAck();
 434   2                      cCheckSum ^= cP[cCnt];
 435   2              }
 436   1              cP[cCnt] = I2CReceiveByte();
 437   1              I2CSendNotAck();
 438   1              I2CStop();
 439   1              if (cCheckSum != cP[cCnt])
 440   1              {
 441   2                      return FAILURE;
 442   2              }
 443   1              else
 444   1              {
 445   2                      return SUCCESS;
 446   2              }
 447   1      }
 448          /*****************************************************************************
 449          发送控制器命令
 450          *****************************************************************************/
 451          unsigned char Send_IIC_Command(unsigned char *cP)
 452          {
 453   1              unsigned char i;
 454   1              unsigned char cCheckSum = 0;
 455   1              I2CStart();
 456   1              I2CSendByte(WRITE_M101XX);
 457   1              if (I2CWaitAck() == SUCCESS)
 458   1              {
 459   2                      for(i=0; i<cP[0]; i++)  
 460   2                      {
 461   3                              cCheckSum ^= cP[i];
 462   3                              I2CSendByte(cP[i]);
 463   3                              if (I2CWaitAck() != SUCCESS)
 464   3                              {
 465   4                                      return FAILURE;
 466   4                              }
 467   3                      }
 468   2                      I2CSendByte(cCheckSum);
 469   2                      if (I2CWaitAck() != SUCCESS)
 470   2                      {
 471   3                              return FAILURE;
 472   3                      }
 473   2                      I2CStop();
 474   2              return SUCCESS;
 475   2              }
 476   1              else
 477   1              {
 478   2                      return FAILURE;
 479   2              }
 480   1      }


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =   1185    ----
   CONSTANT SIZE    =    130    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =     61      30
   IDATA SIZE       =   ----    ----
C51 COMPILER V7.07   M101_2_X_TEST                                                         07/31/2008 19:29:08 PAGE 9   

   BIT SIZE         =      2    ----
END OF MODULE INFORMATION.


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

⌨️ 快捷键说明

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