main.lst

来自「学校水POS读卡程序」· LST 代码 · 共 1,499 行 · 第 1/5 页

LST
1,499
字号
 284          /****************************************************************************
 285          *                                                                           *
 286          * Function:     init                                                        *
 287          *                                                                           *
 288          * Input:        -                                                           *
 289          * Output:       -                                                           *
 290          *                                                                           *
 291          * Description:                                                              *
 292          *                                                                           *
 293          *                                                                           *
 294          ****************************************************************************/
 295          
 296          void    init (void)
 297          {
 298   1      
 299   1        AuthOk      = 0xff;
 300   1      
 301   1        AccOk       = FALSE;
 302   1        //EnOnChipSram();       // Enable w77e58 on chip 1k sram
 303   1        #ifdef w77e58
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 6   

                DME0        = TRUE;
                PMR         = 0x41;
                #endif
 307   1        
 308   1        #ifdef sst89e554
 309   1        AUXR        = 0;
 310   1        #endif
 311   1        LED         = ON;
 312   1        BEEP        = BeepOn;
 313   1        BEEP        = BeepOff;
 314   1        RC500RST    = FALSE;
 315   1        //RC500_CS    = TRUE; // Enable the CS for RC500
 316   1      
 317   1        CmdReceived = FALSE;
 318   1        CmdValid    = FALSE;
 319   1        Quit        = FALSE;
 320   1        LLfReady    = TRUE;
 321   1        SendReady   = TRUE;
 322   1        Idle        = TRUE;
 323   1      
 324   1        RepCnt      = 0;
 325   1      
 326   1        RecvState   = RECV_STX;
 327   1      
 328   1        EnableTransferCmd = FALSE;
 329   1      
 330   1        CheckByteCnt = BCC_CHECKBYTECNT;
 331   1      
 332   1      #ifdef AUTODELAY
 333   1        DelayRate = 0;
 334   1        DelayRateLocked = TRUE;
 335   1      #endif
 336   1      
 337   1        FrameEnd    = 0;
 338   1        FrameHead   = 0;
 339   1        FrameOk     = 0;
 340   1        DataNum     = 0;
 341   1        ChkSum      = 0;
 342   1      
 343   1        PCON = 0x00;                  // SMOD = 1;
 344   1        SCON = 0x50;                  // Mode 1, 8-bit UART, enable receiption
 345   1      
 346   1      //  EIE  = 0x0 ;
 347   1      //  AutoBaud = TRUE;
 348   1        TMOD     = 0x20;              // Timer 1, mode 2, 8-bit auto reload,
 349   1                                      // Timer 0, mode 0, 13-bit counter
 350   1        Capt_L   = 0;
 351   1        Capt_H   = 0;
 352   1      
 353   1        TH1 = 0xfd ;
 354   1        TL1 = 0xfd ;
 355   1      
 356   1        ES = 1 ;
 357   1        TR1 = 1;
 358   1      
 359   1       // LED = 0;
 360   1       // delay_10ms(10);
 361   1       // LED = 1;
 362   1        
 363   1      
 364   1        PX1 = 1;
 365   1        IT1 = 1;                      // Config ext1 as edge trigger for RC500
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 7   

 366   1        EX1 = 1;                      // Enable ext1 interrupt for RC500
 367   1        RC500RST = TRUE;
 368   1        EIE      = 0x0;
 369   1        EA = TRUE;                    // Enable all interrupts
 370   1        OpenIO();
 371   1      }
 372          
 373          
 374          /****************************************************************************
 375          *                                                                           *
 376          * Function:     cmd_execution                                               *
 377          *                                                                           *
 378          * Input:        SerBuffer[]                                                 *
 379          * Output:       SerBuffer[]                                                 *
 380          *                                                                           *
 381          * Description:                                                              *
 382          *                                                                           *
 383          *                                                                           *
 384          ****************************************************************************/
 385          
 386          void    cmd_execution (void)
 387          {
 388   1        uchar xdata Status;
 389   1        uchar xdata len;
 390   1        uchar xdata cmd;
 391   1        uchar xdata adr;
 392   1        uchar xdata tmp[16];
 393   1        //uchar xdata snr[4];
 394   1        uchar xdata size;
 395   1        uchar xdata tt[2];
 396   1        static uchar xdata mode,value[4],addr;
 397   1        Temp = SerBuffer;  
 398   1      
 399   1        cmd = SerBuffer[COMMAND];  //COMMAND == 1
 400   1      
 401   1        switch (cmd)
 402   1        {
 403   2              case 0x40:                                      //PICC_REQALL 
 404   2      
 405   2                Status = M500PiccRequest(PICC_REQALL, tt);    //Get Picc tt[]: Tagtype 2 Byte
 406   2                ErrNum = Status;
 407   2            if (Status != MI_OK)
 408   2                {
 409   3              AccOk = 0;       
 410   3              
 411   3                }
 412   2            else
 413   2            {
 414   3               // RingOn();
 415   3              AccOk = 1;
 416   3            }
 417   2            ErrNum = Status; 
 418   2            break;
 419   2      
 420   2              
 421   2      
 422   2              case 0x41:                                      // Request
 423   2      
 424   2                if(SerBuffer[MODE]&0X01) SerBuffer[MODE]=PICC_REQALL; // ALL
 425   2                else SerBuffer[MODE]=PICC_REQSTD; // IDLE
 426   2      
 427   2                Status = M500PiccRequest(SerBuffer[MODE], &SerBuffer[TAGTYPE]);
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 8   

 428   2            
 429   2                if (Status == MI_OK)
 430   2                {
 431   3                      SerBuffer[LENGTH] = 2;
 432   3                }
 433   2            ErrNum = Status;
 434   2                break;
 435   2      
 436   2      
 437   2              case 0x42:                                      // Anticoll 
 438   2      
 439   2                Status = M500PiccAnticoll(SerBuffer[BCNT], &SerBuffer[SERNR]);
 440   2           
 441   2                if (Status == MI_OK)
 442   2                {
 443   3                      SerBuffer[LENGTH] = 4;
 444   3             // RingOn();
 445   3                  AccOk = 1;
 446   3                }
 447   2            ErrNum = Status;
 448   2                break;
 449   2      
 450   2      
 451   2              case 0x43:                                      // Select
 452   2      
 453   2                memcpy(card_snr,&SerBuffer[SERNR],4); // store serial number in globle var
 454   2      
 455   2      //输入: 卡片序列号 输出:卡片容量 SIZE = 0X88H      
 456   2                Status = M500PiccSelect(&SerBuffer[SERNR], &SerBuffer[SIZE]);
 457   2                if (Status == MI_OK)
 458   2                {
 459   3                      SerBuffer[LENGTH] = 1;
 460   3                }
 461   2      
 462   2           //     RingOn();
 463   2      
 464   2            AccOk = 1;
 465   2            ErrNum = Status;
 466   2      
 467   2                break;
 468   2      
 469   2      
 470   2              case 0x44:                                      // Authentication
 471   2      
 472   2                if(SerBuffer[MODE]&0X04) SerBuffer[MODE]=PICC_AUTHENT1B; // keyB
 473   2                else SerBuffer[MODE]=PICC_AUTHENT1A; // keyA =0x60  MODE =3  key_sector = SerBuffer[4] block = 9 SerBuf
             -fer[SECNR]+1)*4-1 SECNR= 4
 474   2      
 475   2                Status = M500PiccAuth(SerBuffer[MODE], card_snr, SerBuffer[SECNR], (SerBuffer[SECNR]+1)*4-1);
 476   2      
 477   2      //      Status = M500PiccAuthE2(SerBuffer[MODE], card_snr, SerBuffer[SECNR], (SerBuffer[SECNR]+1)*4-1);
 478   2      
 479   2            AuthOk = Status;
 480   2            ErrNum = Status;
 481   2                
 482   2                break;
 483   2      
 484   2      
 485   2              case 0x45:                                      // Halt
 486   2      
 487   2                Status = M500PiccHalt();
 488   2                break;
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 9   

 489   2      
 490   2      
 491   2              case 0x46:                                      // Read
 492   2      
 493   2            Status = M500PiccRead(SerBuffer[ADR], &SerBuffer[ADR]);//ADR = 3
 494   2                if (Status == MI_OK)
 495   2                {
 496   3                      SerBuffer[LENGTH] = 16;
 497   3                }
 498   2            ErrNum = Status;
 499   2                break;
 500   2      
 501   2      
 502   2              case 0x47:                                      // Write
 503   2      
 504   2                Status = M500PiccWrite(SerBuffer[ADR], &SerBuffer[DATABYTES]);
 505   2            ErrNum = Status;
 506   2                break;
 507   2      
 508   2      
 509   2              case 0x48:                                      // Increment
 510   2      
 511   2                mode = PICC_INCREMENT;
 512   2                addr = SerBuffer[ADR];
 513   2                memcpy(value,&SerBuffer[VALUE],4);
 514   2                Status = MI_OK;
 515   2                break;
 516   2      
 517   2      
 518   2              case 0x49:                                      // Decrement
 519   2      
 520   2                mode = PICC_DECREMENT;
 521   2                addr = SerBuffer[ADR];
 522   2                memcpy(value,&SerBuffer[VALUE],4);
 523   2                Status = MI_OK;
 524   2                break;
 525   2      
 526   2      
 527   2              case 0x4A:                                      // Restore
 528   2      
 529   2                mode = PICC_RESTORE;
 530   2                addr = SerBuffer[ADR];
 531   2                memset(value,0,4);
 532   2                Status = MI_OK;
 533   2                break;
 534   2      
 535   2      
 536   2              case 0x4B:                                      // Transfer
 537   2      
 538   2                if (EnableTransferCmd)
 539   2                {
 540   3                      Status = M500PiccValue(mode, addr, value, SerBuffer[ADR]);
 541   3                }
 542   2                else
 543   2                {
 544   3                      Status = MI_CODEERR;
 545   3                }
 546   2                break;
 547   2      
 548   2      
 549   2              case 0x4C:                                      // Load Key
 550   2      
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 10  

 551   2                if(SerBuffer[MODE]&0X04) SerBuffer[MODE]=PICC_AUTHENT1B; // keyB
 552   2                else SerBuffer[MODE]=PICC_AUTHENT1A; // keyA
 553   2      // _____________________________________________________________________________
 554   2      //
 555   2      //  FUNCTION: M500PcdLoadKeyE2
 556   2      //        IN: key_type      PICC_AUTHENT1A or PICC_AUTHENT1B
 557   2      //            sector        key sector number, on which the key should be stored
 558   2      //                          values from 0 to 15 are valid
 559   2      //            uncoded_keys  6 bytes key
 560   2      //       OUT: -
 561   2      //    RETURN:
 562   2      //   COMMENT: This function stores the keys in the reader internal E2PROM.
 563   2      //            These keys are available for the function M500PiccAuthE2.
 564   2      // ______________________________________________________________________________
 565   2      //
 566   2                Status = M500PcdLoadKeyE2(SerBuffer[MODE], SerBuffer[SECNR], &SerBuffer[13]);
 567   2            ErrNum = Status;
 568   2                break;
 569   2      
 570   2      
 571   2              case 0x4D:                                      // comm check char
 572   2      

⌨️ 快捷键说明

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