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

📄 main.lst

📁 keilc写RFID独T5557卡的源程序,
💻 LST
📖 第 1 页 / 共 3 页
字号:
 267          
 268          uchar Prepare_Addr( uchar addr ) 
 269          {
 270   1              *forward_ptr++ = (addr>>2);  
 271   1              *forward_ptr++ = (addr>>1);
 272   1              *forward_ptr++ = addr; 
 273   1      
 274   1              return 3;                      //return number of emited bits
 275   1      }
 276          
 277          uchar Prepare_Data( uchar *data_tx) 
 278          {
 279   1              register uchar i, j;
 280   1              register uchar datas;
 281   1              for(j=1; j<5; j++) 
 282   1              {
 283   2                      datas = *(data_tx + j);
 284   2                      for(i=8; i>0; i--)
 285   2                      {
 286   3                              *forward_ptr++ = (datas >> (i-1));
 287   3                      }               
 288   2              }
 289   1              return 32;                             //return number of emited bits
 290   1      }
 291          
 292          
 293          // Forward Link setup function
 294          // Requires: forwarLink_data filled with valid bits (1 bit per byte)
 295          //           fwd_bit_count set with number of bits to be sent
 296          void SendForward(uchar fwd_bit_count) 
 297          {
 298   1              uchar sync=1;
 299   1              fwd_write_ptr = forwardLink_data;
 300   1              fwd_bit_sz = fwd_bit_count;
 301   1              fwd_bit_phase = 3;
 302   1              field_stop = fwd_1st_pulse;             //fwd_1st_pulse = 256-20
C51 COMPILER V7.50   MAIN                                                                  09/17/2007 14:50:28 PAGE 6   

 303   1      
 304   1              TR0=0;
 305   1              TH0=0xff;TL0=1;          //minimum startup pulse length,255
 306   1              MOD=0;                   
 307   1              TF0=0;                   
 308   1              ET0=0;                          //disable T0 interrupt         
 309   1              TMOD=(TMOD|0x05);                       //计数器,16位计数器
 310   1              TR0=1;     
 311   1      
 312   1        // waiting for clearing T0IE0 => command sending
 313   1              while (!TF0) 
 314   1              {
 315   2              if ((sync == 1) && (!DEMOD_OUT))  
 316   2                      sync = 0;
 317   2              if ((sync == 0) && (DEMOD_OUT))  
 318   2                      break;
 319   2              }
 320   1              MOD=1;                  //force 1st mod pulse
 321   1              fwd_bit_sz--;           //prepare next bit modulation
 322   1              fwd_write_ptr++;
 323   1              TF0=0;                  //clear any pending flag
 324   1              TR0=0;
 325   1              TH0=0xFF;TL0= 255-60;
 326   1              TR0=1;
 327   1              field_stop = fwd_01_stop;           
 328   1              fwd_bit_phase = 2;
 329   1              ET0=1;                 //enable overflow interrupt
 330   1      
 331   1        // waiting for clearing T0IE0 => command sending
 332   1              while ( ET0== 1 ) ;
 333   1      }
 334          
 335          
 336          
 337          //读卡程序, Manchester解码
 338          void ManchesterRead(void)
 339          {
 340   1              uchar i,j;
 341   1              uchar   captured_bits_count;
 342   1              //ClearCaptureBuffers();
 343   1              captured_bit_count = 0;
 344   1              capture_cnt = 0;
 345   1              captured_byte=0;
 346   1              capture_check=0;
 347   1              capture_check_count=0;
 348   1              buffer_capture_check=0;
 349   1              compute_capture_check=0;
 350   1              check_stat=0;
 351   1      
 352   1      
 353   1              
 354   1              TR2 = 0; 
 355   1              TF2 = 0;      
 356   1              TL2 = 0;//(uchar)(~maxCaptureTimeLow);          //0xd7
 357   1              TH2 = 0;//(uchar)((~maxCaptureTimeLow)>>8);     //0xf0, //set timer with initial time
 358   1              currentMaxTimeHi = ~maxCaptureTimeHi;   //0xff
 359   1      
 360   1              last_capture = 0;//~maxCaptureTimeLow;          //~0x0f28
 361   1              capture_read_time_data_ptr = capture_time;              // capture ptr
 362   1      
 363   1              flag_wait=1;
 364   1              ET2=1;                          //enable t2 interrupt
C51 COMPILER V7.50   MAIN                                                                  09/17/2007 14:50:28 PAGE 7   

 365   1      
 366   1              check_stat=ERR_EM4469_NEITHER_ACK;              //if read card ok,check_stat will change
 367   1      
 368   1              cap_count = 0;
 369   1              TR2=1;  //                   
 370   1              while ( flag_wait )             //接收
 371   1              {
 372   2                      for(i=0;i<0xf0;i++)
 373   2                      {
 374   3                              if(DEMOD_OUT == 0)
 375   3                                      break;
 376   3                      }
 377   2                      if(i>=0xf0)
 378   2                              return;
 379   2                      capture();                                      //hi电平时间
 380   2                      cap_count++;
 381   2                      for(i=0;i<0xf0;i++)
 382   2                      {
 383   3                              if(DEMOD_OUT == 1)
 384   3                                      break;
 385   3                      }
 386   2                      if(i>=0xf0)
 387   2                              return;
 388   2                      capture();                                      //low电平时间
 389   2                      cap_count++;
 390   2                      if(cap_count > 150)
 391   2                              break;  
 392   2              }
 393   1              //capture_time[253]= cap_count;
 394   1              //trace(capture_time,254);
 395   1              check_stat=ERR_EM4469_NEITHER_ACK;
 396   1              for(j=0;j<10;j++)
 397   1              {
 398   2                      if(((halfDataRate*2+8)<capture_time[j])&&(capture_time[j]<(halfDataRate*3+8))
 399   2                      &&(capture_time[j+1]<MaxCaptureHalfDateRate)&&(capture_time[j+2]>MaxCaptureHalfDateRate)
 400   2                      &&(capture_time[j+2]<(halfDataRate*3+8)))
 401   2                              break;
 402   2              }
 403   1              if(j==10)
 404   1              {
 405   2                      check_stat=0xf1;
 406   2                      
 407   2                      return;
 408   2              }
 409   1              check_stat = UART_MESSAGE_OK;
 410   1              if(capture_time[j+2]<(halfDataRate*2+8))
 411   1              {
 412   2                      //bit_begin = 1;
 413   2                      store_bit(0);
 414   2                      b_edge = 0;
 415   2                      j=j+4;
 416   2              }
 417   1              else if((capture_time[j+2]>(halfDataRate*2+8))&&(capture_time[j+2]<(halfDataRate*3+8)))
 418   1              {
 419   2                      //bit_begin = 0;
 420   2                      store_bit(1);
 421   2                      b_edge = 1;
 422   2                      j=j+3;
 423   2              }
 424   1              else 
 425   1              {
 426   2                      check_stat=0xf2;
C51 COMPILER V7.50   MAIN                                                                  09/17/2007 14:50:28 PAGE 8   

 427   2                      return;
 428   2              }
 429   1              
 430   1              captured_bits_count=1;
 431   1              captured_bits_count++;
 432   1              if (check_stat==UART_MESSAGE_OK)
 433   1              {
 434   2                      //解码
 435   2                      for (i=0;i<150;i++)
 436   2                      {
 437   3                              if (capture_time[j]<MaxCaptureHalfDateRate)
 438   3                              {
 439   4                                      if((i%2)==0)    
 440   4                                      {
 441   5                                              store_bit(b_edge);
 442   5                                      }
 443   4                                      else
 444   4                                      {
 445   5                                              store_bit(!b_edge);
 446   5                                      }
 447   4                                      i++;
 448   4                                      j++;
 449   4                                      captured_bits_count++;
 450   4                                      if (captured_bits_count>64) //32位数据结构
 451   4                                              break;
 452   4                              }
 453   3                              else if((capture_time[j]>MaxCaptureHalfDateRate) &&(capture_time[j]<MaxCaptureDateRate))
 454   3                              {
 455   4                                      if((i%2)==0)    
 456   4                                      {
 457   5                                              store_bit(!b_edge);
 458   5                                      }
 459   4                                      else
 460   4                                      {
 461   5                                              store_bit(b_edge);
 462   5                                      }
 463   4                                      captured_bits_count++;
 464   4                                      if (captured_bits_count>64) //45位数据结构
 465   4                                              break;
 466   4                              }
 467   3                              else  
 468   3                              {
 469   4                                      check_stat=0xf3;
 470   4                                      break;
 471   4                              }
 472   3                              j++;
 473   3                      }
 474   2              }
 475   1              for(i=0;i<150;i++)      //2006-5-13 14:19
 476   1              {
 477   2                      capture_time[i]=0xff;
 478   2              }       
 479   1              
 480   1              //trace(capture_time,120);
 481   1              //trace(capture_data,32);
 482   1              
 483   1      }
 484          
 485          //写卡程序,Manchester解码
 486          void ManchesterWrite(void)
 487          {
 488   1              uchar i,j;
C51 COMPILER V7.50   MAIN                                                                  09/17/2007 14:50:28 PAGE 9   

 489   1              ClearCaptureBuffers();
 490   1              captured_bit_count = 0;
 491   1              capture_cnt = 0;
 492   1              captured_byte=0;
 493   1              capture_check=0;
 494   1              capture_check_count=0;
 495   1              buffer_capture_check=0;
 496   1              compute_capture_check=0;
 497   1              check_stat=0;
 498   1              TR2 = 0; 
 499   1              TF2=0;      //clear pending interrupts
 500   1              TL2=(uchar)(~maxCaptureTimeLow); TH2=(uchar)((~maxCaptureTimeLow)>>8) ;             //set timer with init
             -ial time
 501   1              currentMaxTimeHi = ~maxCaptureTimeHi;
 502   1              last_capture=~maxCaptureTimeLow; 
 503   1              capture_read_time_data_ptr=capture_time;
 504   1              flag_wait=1;ET2=1;
 505   1      
 506   1      
 507   1      
 508   1              TR2=1;                     
 509   1              while ( flag_wait )         
 510   1              {
 511   2                      for(i=0;i<0xf0;i++)
 512   2                      {
 513   3                              if(DEMOD_OUT == 0)              //等待低电平,超时退出
 514   3                                      break;
 515   3                      }
 516   2                      if(i>=0xf0)
 517   2                      {
 518   3                              for(i=0;i<120;i++)
 519   3                              {
 520   4                                      capture_time[i]=0xff;
 521   4                              }
 522   3                              return;
 523   3                      }
 524   2      
 525   2                      capture();
 526   2      
 527   2                      for(i=0;i<0xf0;i++)
 528   2                      {
 529   3                              if(DEMOD_OUT == 1)              //等待高电平,超时退出
 530   3                                      break;
 531   3                      }
 532   2                      if(i>=0xf0)
 533   2                      {
 534   3                              for(i=0;i<120;i++)
 535   3                              {
 536   4                                      capture_time[i]=0xff;
 537   4                              }
 538   3                              return;
 539   3                      }
 540   2      
 541   2                      capture();

⌨️ 快捷键说明

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