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

📄 main.lst

📁 hs4905非接触卡读卡机芯片读4442的源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 742   4                                      bit_subscript=(k%8);
 743   4                                      custID=(custID|(((autodection_data[array_subscript]&(1<<bit_subscript))>>bit_subscript)<<bit_number));
 744   4                                      bit_number++;                                           
 745   4                              }
 746   3                              for (k=(j+15);k<(j+19);k++)
 747   3                              {
 748   4                                      array_subscript=(k/8);
 749   4                                      bit_subscript=(k%8);
 750   4                                      custID=(custID|(((autodection_data[array_subscript]&(1<<bit_subscript))>>bit_subscript)<<bit_number));
 751   4                                      bit_number++;                                           
 752   4                              }
 753   3                              //data
 754   3                              k=0;
 755   3                              bit_number=0;
 756   3                              for(l=(j+20);l<(j+59);l++)
 757   3                              {
 758   4                                      if (((l-j-20)%5)!=4)
 759   4                                      {
 760   5                                              array_subscript=(l>>3);
 761   5                                              bit_subscript=(l%8);
 762   5                                              DataItem[k]=(DataItem[k]|(((autodection_data[array_subscript]&(1<<bit_subscript))>>bit_subscript)<<bi
             -t_number));                                                                
 763   5                                              bit_number++;
 764   5                                              if (bit_number==8) 
 765   5                                              {
 766   6                                                      bit_number=0;
 767   6                                                      k++;
 768   6                                              }
 769   5                                      } 
 770   4                              }                                               
 771   3                      }
 772   2              }                       
 773   1      
 774   1              
 775   1              
 776   1              //向PC返回响应信息
 777   1              check_stat=0x14;
 778   1              if (flag_column_check==1) 
 779   1              {
 780   2                      check_stat=0;
 781   2                      flag_column_check=0;
 782   2              }
 783   1              tx_buff[0]=0x02;
 784   1              tx_buff[1]=0x0a;
 785   1              tx_buff[2]=0x86;
 786   1              tx_buff[3]=check_stat;
 787   1              tx_buff[4]=1;                           //RF/64
 788   1              tx_buff[5]=custID;
 789   1              tx_buff[6]=DataItem[3];                 //读EM4100数据位倒置
 790   1              tx_buff[7]=DataItem[2];
 791   1              tx_buff[8]=DataItem[1];
 792   1              tx_buff[9]=DataItem[0];
 793   1              tx_buff[10]=(tx_buff[1]^tx_buff[2]^tx_buff[3]^tx_buff[4]^tx_buff[5]^tx_buff[6]^tx_buff[7]^tx_buff[8]^tx_b
             -uff[9]);
 794   1              tx_buff[11]=0x03;
C51 COMPILER V7.50   MAIN                                                                  06/07/2006 18:04:04 PAGE 14  

 795   1              trace(tx_buff,12);
 796   1      }
 797          
 798          uchar Prepare_Cmd( uchar cmd ) 
 799          {
 800   1              register uchar line_parity;
 801   1      
 802   1          *forward_ptr++ = 0;               //start bit
 803   1          *forward_ptr++ = 0;               
 804   1      
 805   1              *forward_ptr++ = cmd;
 806   1              line_parity = cmd;
 807   1              cmd >>= 1;
 808   1              *forward_ptr++ = cmd;
 809   1              line_parity ^= cmd;
 810   1               cmd >>= 1;
 811   1              *forward_ptr++ = cmd;
 812   1              line_parity ^= cmd;
 813   1              *forward_ptr++ = (line_parity & 1);     
 814   1          return 6;                           
 815   1      }
 816          
 817          
 818          uchar Prepare_Addr( uchar addr ) 
 819          {
 820   1              register uchar line_parity;
 821   1              *forward_ptr++ = addr;
 822   1              line_parity = addr;
 823   1              addr >>= 1;  
 824   1              *forward_ptr++ = addr;
 825   1              line_parity ^= addr;
 826   1              addr >>= 1;  
 827   1              *forward_ptr++ = addr;
 828   1              line_parity ^= addr;
 829   1              addr >>= 1;  
 830   1              *forward_ptr++ = addr;
 831   1              line_parity ^= addr;
 832   1              *forward_ptr++ = 0;
 833   1              *forward_ptr++ = 0;
 834   1              *forward_ptr++ = (line_parity & 1);
 835   1              return 7;                      //return number of emited bits
 836   1      }
 837          
 838          
 839          
 840          uchar Prepare_Data( uint data_low, uint data_hi) 
 841          {
 842   1              register uchar line_parity;
 843   1              register uchar column_parity;
 844   1              register uchar i, j;
 845   1              register uint datas;
 846   1      
 847   1              datas = data_low;
 848   1              column_parity = 0;
 849   1      
 850   1              for(i=0; i<4; i++) 
 851   1              {
 852   2              line_parity = 0;
 853   2              for(j=0; j<8; j++) 
 854   2              {
 855   3                      line_parity ^= datas;
 856   3                      column_parity ^= (datas&1) << j;
C51 COMPILER V7.50   MAIN                                                                  06/07/2006 18:04:04 PAGE 15  

 857   3                      *forward_ptr++ = datas;
 858   3                      datas >>= 1;
 859   3              }
 860   2              *forward_ptr++ = line_parity;
 861   2              if(i == 1)
 862   2                      datas = data_hi;
 863   2              }
 864   1      
 865   1              for(j=0; j<8; j++) 
 866   1              {
 867   2              *forward_ptr++ = column_parity;
 868   2              column_parity >>= 1;
 869   2              }
 870   1              *forward_ptr = 0;
 871   1      
 872   1              return 45;                             //return number of emited bits
 873   1      }
 874          
 875          // Forward Link setup function
 876          // Requires: forwarLink_data filled with valid bits (1 bit per byte)
 877          //           fwd_bit_count set with number of bits to be sent
 878          void SendForward(uchar fwd_bit_count) 
 879          {
 880   1              uchar sync=1;
 881   1              fwd_write_ptr = forwardLink_data;
 882   1              fwd_bit_sz = fwd_bit_count;
 883   1              fwd_bit_phase = 3;
 884   1              field_stop = fwd_1st_pulse;             //fwd_1st_pulse = 256-20
 885   1      
 886   1              TR0=0;
 887   1              TH0=0xff;TL0=1;          //minimum startup pulse length,255
 888   1              MOD=0;                   
 889   1              TF0=0;                   
 890   1              ET0=0;                          //disable T0 interrupt         
 891   1              TMOD=(TMOD|0x05);                       //计数器,16位计数器
 892   1              TR0=1;     
 893   1      
 894   1        // waiting for clearing T0IE0 => command sending
 895   1              while (!TF0) 
 896   1              {
 897   2              if ((sync == 1) && (!DEMOD_OUT))  
 898   2                      sync = 0;
 899   2              if ((sync == 0) && (DEMOD_OUT))  
 900   2                      break;
 901   2              }
 902   1              MOD=1;                  //force 1st mod pulse
 903   1              fwd_bit_sz--;           //prepare next bit modulation
 904   1              fwd_write_ptr++;
 905   1              TF0=0;                  //clear any pending flag
 906   1              TR0=0;
 907   1              TH0=0xFF;TL0= field_stop;
 908   1              TR0=1;
 909   1              field_stop = fwd_01_stop;           
 910   1              fwd_bit_phase = 2;
 911   1              ET0=1;                 //enable overflow interrupt
 912   1      
 913   1        // waiting for clearing T0IE0 => command sending
 914   1              while ( ET0== 1 ) ;
 915   1      }
 916          
 917          
 918          void Wait(uint period) 
C51 COMPILER V7.50   MAIN                                                                  06/07/2006 18:04:04 PAGE 16  

 919          {
 920   1              TR2 = 0;                             
 921   1              TF2=0;      
 922   1              TL2=(uchar)(~period);  TH2=(uchar)((~period)>>8);                      
 923   1              currentMaxTimeHi = 0xFF;
 924   1              ET2=1;
 925   1              TR2=1;                    
 926   1              flag_wait=1;
 927   1              while ( flag_wait);   
 928   1      }
 929          
 930          //读卡程序, Manchester解码
 931          void ManchesterRead(void)
 932          {
 933   1              uchar i,j;
 934   1              uchar   captured_bits_count;
 935   1              ClearCaptureBuffers();
 936   1              captured_bit_count = 0;
 937   1              capture_cnt = 0;
 938   1              captured_byte=0;
 939   1              capture_check=0;
 940   1              capture_check_count=0;
 941   1              buffer_capture_check=0;
 942   1              compute_capture_check=0;
 943   1              check_stat=0;
 944   1      
 945   1              for(i=0;i<120;i++)      //2006-5-13 14:19
 946   1              {
 947   2                      capture_time[i]=0xff;
 948   2              }       
 949   1              
 950   1              TR2 = 0; 
 951   1              TF2 = 0;      
 952   1              TL2 = (uchar)(~maxCaptureTimeLow);              //0xd7
 953   1              TH2 = (uchar)((~maxCaptureTimeLow)>>8); //0xf0, //set timer with initial time
 954   1              currentMaxTimeHi = ~maxCaptureTimeHi;   //0xff
 955   1      
 956   1              last_capture = ~maxCaptureTimeLow;              //~0x0f28
 957   1              capture_read_time_data_ptr = capture_time;              // capture ptr
 958   1      
 959   1              flag_wait=1;
 960   1              ET2=1;                          //enable t2 interrupt
 961   1      
 962   1              check_stat=ERR_EM4469_NEITHER_ACK;              //if read card ok,check_stat will change
 963   1              for(i=0;i<0xf0;i++)
 964   1              {
 965   2                      if(DEMOD_OUT == 0)              //等待低电平,超时退出
 966   2                              break;
 967   2              }
 968   1              if(i>=0xf0)
 969   1              {
 970   2                      for(i=0;i<120;i++)
 971   2                      {
 972   3                              capture_time[i]=0xff;
 973   3                      }
 974   2                      return;
 975   2              }
 976   1              
 977   1              for(i=0;i<0xf0;i++)
 978   1              {
 979   2                      if(DEMOD_OUT == 1)              //等待高电平,超时退出
 980   2                              break;
C51 COMPILER V7.50   MAIN                                                                  06/07/2006 18:04:04 PAGE 17  

 981   2              }
 982   1              if(i>=0xf0)
 983   1              {
 984   2                      for(i=0;i<120;i++)
 985   2                      {
 986   3                              capture_time[i]=0xff;
 987   3                      }
 988   2                      return;
 989   2              }
 990   1              

⌨️ 快捷键说明

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