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

📄 main.lst

📁 hs4905非接触卡读卡机芯片读t5557 的源代码
💻 LST
📖 第 1 页 / 共 5 页
字号:
 246   3                                      break;
 247   3      /*      
 248   3                              case 0x80 :
 249   3                                      ReadWordToPC();         //读卡
 250   3                                      break;
 251   3                              case 0x81 :
 252   3                                      WriteWordtoCard();              //写卡
 253   3                                      break;
 254   3                              case 0x82 :
 255   3                                      Login();                        //
 256   3                                      break;
 257   3                              case 0x83 :
 258   3                                      Disable();
 259   3                                      break;
 260   3                              case 0x84 : 
 261   3                                      PCLinkReader();         //PC要求与读卡器连接
 262   3                                      break;
 263   3                              case 0x85 : 
 264   3                                      //DefaultRead();                //
 265   3                                      break;
 266   3                              case 0x86 : 
 267   3                                      Readonly_autodetection();               //只读,自动检测,可读4100,配置4469,读4469
 268   3                                      break;                  
 269   3                              case 0xFB :
 270   3                                      GetReaderConfiguration();               //读取读卡器的配置参数
 271   3                                      break;
 272   3                              case 0xFC :
 273   3                                      SetReaderConfiguration();               //设置读卡器的配置参数
 274   3                                      break;
 275   3                              case 0xFD :
 276   3                                      ReadStatusToPC();                               //读卡
 277   3                                      break;
 278   3                              case 0xFE : 
 279   3                                      FieldSwitch();
 280   3                                      break;
 281   3      */              
 282   3                              default : 
 283   3                                      break;
 284   3                      }
 285   2              }
 286   1      }
 287          /*
 288          //读卡数据,区地址=rx_buff[3],发送到PC,本版本支持的PC演示软件可以看到相应的数据
 289          void ReadWordToPC(void)
 290          {
 291                  uchar fwd_bit_count;    
 292                  fwd_bit_count = Prepare_Cmd( FWD_CMD_READ );
 293                  fwd_bit_count += Prepare_Addr(rx_buff[1]);
 294                  SendForward(fwd_bit_count);             
 295                  Wait(tpp_period);                 
 296                  maxCaptureTimeLow = maxTRead;           //=3880
 297                  maxCaptureTimeHi = 0;             
 298                  ManchesterRead();                       
 299                  tx_buff[0]=0x02;                //帧头
 300                  tx_buff[1]=0x09;                //帧信息长度,从tx_buff[2]开始计算,到tx_buff[10]=0x03结束
 301                  tx_buff[2]=0x80;                //命令字
 302                  tx_buff[3]=check_stat;
C51 COMPILER V7.50   MAIN                                                                  08/14/2006 15:15:34 PAGE 6   

 303                  tx_buff[4]= rx_buff[3];         //地址
 304                  tx_buff[5]=capture_data[0];     //数据
 305                  tx_buff[6]=capture_data[1];     //数据
 306                  tx_buff[7]=capture_data[2];     //数据
 307                  tx_buff[8]=capture_data[3];     //数据
 308                  tx_buff[9]=(tx_buff[1]^tx_buff[2]^tx_buff[3]^tx_buff[4]^tx_buff[5]^tx_buff[6]^tx_buff[7]^tx_buff[8]);
 309                  //tx_buff[9]是校验和
 310                  tx_buff[10]=0x03;               //帧结束标志
 311                  trace(tx_buff,11);              //发送到PC 11个字节
 312          }
 313          
 314          //写PC传过来的数据到ID卡上
 315          void WriteWordtoCard(void)
 316          {
 317                  uchar fwd_bit_count;
 318          
 319                  fwd_bit_count = Prepare_Cmd( FWD_CMD_WRITE );
 320                  fwd_bit_count += Prepare_Addr(rx_buff[1]);
 321                  fwd_bit_count += Prepare_Data(( ((uint)rx_buff[5] << 8) + rx_buff[4]), ( ((uint)rx_buff[7] << 8) + rx_b
             -uff[6]));
 322                  if (rx_buff[3] == 0x04)
 323                  {                       //32位配置字
 324                          
 325                          halfDataRate = 32;// datarate = RF/64
 326                          MaxCaptureHalfDateRate = halfDataRate + (halfDataRate >> 1);    //=48
 327                          MaxCaptureDateRate = halfDataRate + halfDataRate + (halfDataRate >> 1);         //=80
 328                          lwr = config_lwr;
 329                          delayed = config_delayed;
 330                          raw = config_raw;
 331                          //forward_link_type = 0x01; 
 332                          maxTLogin = 4 + (4 + 9) * 2 * (uint)halfDataRate;
 333                          maxTWrite = 1144 + (4 + 8) * 2 * (uint)halfDataRate;
 334                          maxTWriteRaw = 1144 + (4 + 5 + 54) * 2 * (uint)halfDataRate;
 335                          maxTRead = (100) + 4 + (5 + 54) * 2 * (uint)halfDataRate;
 336                          maxTDisable = maxTLogin;
 337                          maxTDefaultRead = 2*((lwr-4)*4*8)*2*((uint32)halfDataRate);
 338                          tpp_period = 4 + 2 * (uint)halfDataRate - 4;
 339                          twr_period = (68 + 64 + 896 + 116) + 2 * (uint)halfDataRate - 4;
 340                  }
 341          
 342                  SendForward(fwd_bit_count);     
 343                  Wait(twr_period);
 344                  maxCaptureTimeHi = 0;
 345                  maxCaptureTimeLow = maxTWrite;
 346                  
 347                  ManchesterWrite();
 348          
 349                  tx_buff[0]=0x02;
 350                  tx_buff[1]=0x04;
 351                  tx_buff[2]=0x81;
 352                  tx_buff[3]=check_stat;
 353                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
 354                  tx_buff[5]=0x03;
 355                  trace(tx_buff,6);
 356          }
 357          
 358          //控制天线命令
 359          void FieldSwitch(void)
 360          {
 361                  if (rx_buff[3] & 1 )
 362                  {
 363                          SHD=0;                  //打开天线
C51 COMPILER V7.50   MAIN                                                                  08/14/2006 15:15:34 PAGE 7   

 364                  }
 365                  else 
 366                  {
 367                          SHD=1;                  // 关闭天线
 368                  }
 369                  tx_buff[0]=0x02;                //帧头
 370                  tx_buff[1]=0x04;                //长度
 371                  tx_buff[2]=0xfe;                //命令
 372                  tx_buff[3]=0;
 373                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);          //检验和
 374                  tx_buff[5]=0x03;                //帧结束
 375                  trace(tx_buff,6);
 376          }
 377          
 378          //不可用,匹配PC演示程序,直接返回 设置成功
 379          void SetReaderConfiguration(void)
 380          {
 381                  tx_buff[0]=0x02;
 382                  tx_buff[1]=0x04;
 383                  tx_buff[2]=0xfc;
 384                  tx_buff[3]=0;
 385                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
 386                  tx_buff[5]=0x03;
 387                  trace(tx_buff,6);
 388          }
 389          
 390          //读取DEMO读卡器的配置参数
 391          void GetReaderConfiguration(void)
 392          {
 393                  uchar q;        
 394                  q = 1;                                   
 395                  get_settings_low = (q<<6) | (halfDataRate - 1);
 396                  q = (q >> 2) | (delayed << 4) | ((lwr & 3) << 6);
 397                  get_settings_low |= (uint)q << 8;
 398                  get_settings_hi = ((raw << 6) | (lwr >> 2));// | (forward_link_type >> 1);
 399          
 400                  tx_buff[0]=0x02;
 401                  tx_buff[1]=0x08;
 402                  tx_buff[2]=0xfb;
 403                  tx_buff[3]=0;
 404                  tx_buff[4]=(uchar)get_settings_low;
 405                  tx_buff[5]=get_settings_low>>8;
 406                  tx_buff[6]=(uchar)get_settings_hi;
 407                  tx_buff[7]=get_settings_hi>>8;
 408                  tx_buff[8]=(tx_buff[1]^tx_buff[2]^tx_buff[3]^tx_buff[4]^tx_buff[5]^tx_buff[6]^tx_buff[7]);
 409                  tx_buff[9]=0x03;
 410                  trace(tx_buff,10);
 411          }
 412          
 413          void Disable(void)
 414          {
 415                  uchar fwd_bit_count;
 416              fwd_bit_count = Prepare_Cmd( FWD_CMD_DISABLE );
 417              fwd_bit_count += Prepare_Data( 0xFFFF, 0xFFFF );
 418              SendForward(fwd_bit_count);    
 419              Wait(tpp_period);      
 420              maxCaptureTimeLow = maxTDisable; 
 421              maxCaptureTimeHi = 0;
 422          
 423                  ManchesterRead();
 424          
 425                  tx_buff[0]=0x02;
C51 COMPILER V7.50   MAIN                                                                  08/14/2006 15:15:34 PAGE 8   

 426                  tx_buff[1]=0x04;
 427                  tx_buff[2]=0x83;
 428                  tx_buff[3]=check_stat;
 429                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
 430                  tx_buff[5]=0x03;
 431                  trace(tx_buff,6);
 432          }
 433          
 434          void Login(void)
 435          {
 436                  uchar fwd_bit_count;
 437                  fwd_bit_count = Prepare_Cmd( FWD_CMD_LOGIN );
 438                  fwd_bit_count += Prepare_Data(( ((uint)rx_buff[4] << 8) + rx_buff[3]), ( ((uint)rx_buff[6] << 8) + rx_buf
             -f[5]));
 439                  SendForward(fwd_bit_count);
 440                  Wait(tpp_period);
 441                  maxCaptureTimeLow = maxTLogin; 
 442              maxCaptureTimeHi = 0;
 443                  ManchesterWrite();
 444                  tx_buff[0]=0x02;
 445                  tx_buff[1]=0x04;
 446                  tx_buff[2]=0x82;
 447                  tx_buff[3]=check_stat;
 448                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
 449                  tx_buff[5]=0x03;
 450                  trace(tx_buff,6);
 451          }
 452          
 453            
 454          void PCLinkReader(void)
 455          {
 456                  tx_buff[3]=UART_MESSAGE_OK;
 457                  tx_buff[0]=0x02;
 458                  tx_buff[1]=0x04;
 459                  tx_buff[2]=0x84;
 460                  tx_buff[4]=(tx_buff[1]^tx_buff[2]^tx_buff[3]);
 461                  tx_buff[5]=0x03;
 462                  trace(tx_buff,6);
 463                  speak_on();
 464          }
 465          
 466          void Readonly_autodetection(void)
 467          {
 468                  uchar i,j,k,l;
 469                  
 470                  uchar idata autodection_data[32];
 471                  uchar array_subscript;  //小标
 472                  uchar bit_subscript;            
 473                  uint capt;
 474                  uint icr; 
 475                  bit flag_RO_last_capt_half=0;           
 476                  uchar count_autodection_bit=0;
 477                  bit flag_header_found=0;                
 478                  bit flag_stop_found=0;          
 479                  bit flag_line_check=0;          
 480                  bit flag_column_check=0;                
 481                  uchar check=0;          
 482                  uchar custID=0;
 483                  uchar idata DataItem[4]={0,0,0,0};
 484                  uchar bit_number;
 485                  bit flag_tag_datarate_bigger;           
 486                  bit flag_invalid_edge_manchester;       
C51 COMPILER V7.50   MAIN                                                                  08/14/2006 15:15:34 PAGE 9   

 487                  uchar times_capture_manchester; 
 488             
 489                  //halfDataRate = 32;//config_data_rate+1;
 490                  MaxCaptureHalfDateRate = 48;//halfDataRate+(halfDataRate>>1);
 491                  MaxCaptureDateRate = 80;//halfDataRate+halfDataRate+(halfDataRate>>1);
 492                  //lwr = 7;//config_lwr;
 493                  //maxTDefaultRead = 0x3000;//2*((lwr-4)*4*8)*2*((uint32)halfDataRate);
 494                  maxCaptureTimeLow = 0x3000;//(uint)maxTDefaultRead; 
 495                  maxCaptureTimeHi = 0x30;//(uchar)(maxTDefaultRead >> 16);
 496                  last_capture = 0xcfff;//~maxCaptureTimeLow; 
 497                  TF2 = 0;
 498                  TR2 = 0;                      

⌨️ 快捷键说明

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