📄 m500auc.lst
字号:
321 1 MpIsrInfo = info;
322 1 MpIsrOut = rcv;
323 1 info->irqSource = 0x0;
324 1
325 1 info->nBitsReceived = -(ReadIO(RegBitFraming) >> 4);
326 1 irqEn = 0x3D;
327 1 waitFor = 0x04;
328 1
329 1
330 1 if (status == MI_OK) //如果没有错误
331 1 {
332 2 irqEn |= 0x20;
333 2 waitFor |= 0x20;
334 2 timecnt=1000;
335 2 WriteIO(RegInterruptEn,irqEn | 0x80);
336 2 WriteIO(RegCommand,0x1E); //发送命令
337 2 for(i=0;i<200;i++)
338 2 {
339 3 if(info->nBytesReceived) //取得应答
340 3 {
341 4 MpIsrInfo->status=0;
342 4 info->status=0;
343 4 break;
344 4 }
345 3 delay_1ms(tt0);
346 3 }
347 2
348 2 WriteIO(RegInterruptEn,0x7F);
349 2 WriteIO(RegInterruptRq,0x7F);
350 2 SetBitMask(RegControl,0x04);
351 2 WriteIO(RegCommand,PCD_IDLE); //通知RC500命令执行完毕
352 2 if(i==200) status = MI_NOTAGERR; //如果在200ms内没有取得应答,返回错误代码
353 2 else
354 2 status = MpIsrInfo->status;
355 2
356 2 if (status == MI_OK) //根据错误代码返回不同的status值
357 2 {
358 3 if (tmpStatus = (ReadIO(RegErrorFlag) & 0x17))
359 3 {
360 4 if (tmpStatus & 0x01)
361 4 {
362 5 info->collPos = ReadIO(RegCollPos);
363 5 status = MI_COLLERR;
364 5 }
365 4 else
C51 COMPILER V6.02 M500AUC 11/20/2007 16:53:51 PAGE 7
366 4 {
367 5 info->collPos = 0;
368 5 if (tmpStatus & 0x02)
369 5 {
370 6 status = MI_PARITYERR;
371 6 }
372 5 }
373 4 if (tmpStatus & 0x04)
374 4 {
375 5 status = MI_FRAMINGERR;
376 5 }
377 4 if (tmpStatus & 0x10)
378 4 {
379 5 FlushFIFO();
380 5 status = MI_OVFLERR;
381 5 }
382 4 if (tmpStatus & 0x08)
383 4 {
384 5 status = MI_CRCERR;
385 5 }
386 4 if (status == MI_OK)
387 4 status = MI_NY_IMPLEMENTED;
388 4 }
389 3
390 3 lastBits = ReadIO(RegSecondaryStatus) & 0x07; //判断是否有CRC效验
391 3 if (lastBits)
392 3 info->nBitsReceived += (info->nBytesReceived-1) * 8 + lastBits;
393 3 else
394 3 info->nBitsReceived += info->nBytesReceived * 8;
395 3
396 3 }
397 2 else
398 2 {
399 3 info->collPos = 0x00;
400 3 }
401 2 }
402 1 MpIsrInfo = 0;
403 1 MpIsrOut = 0;
404 1 MpIsrOut = 0;
405 1 tt0=1;
406 1 return status;
407 1 }
408
409 uchar SetBitMask(unsigned char reg,unsigned char mask) //将RC500中某一寄存器的数据的某几位置1
410 {
411 1 char idata tmp = 0x0;
412 1
413 1 tmp = ReadIO(reg);
414 1 WriteIO(reg,tmp | mask); // set bit mask
415 1 return 0x0;
416 1 }
417
418 uchar ClearBitMask(unsigned char reg,unsigned char mask) //将RC500中某一寄存器的数据的某几位清0
419 {
420 1 char idata tmp = 0x0;
421 1
422 1 tmp = ReadIO(reg);
423 1 WriteIO(reg,tmp & ~mask); // clear bit mask
424 1 return 0x0;
425 1 }
426
427 void FlushFIFO(void) //清空FIFO
C51 COMPILER V6.02 M500AUC 11/20/2007 16:53:51 PAGE 8
428 {
429 1 SetBitMask(RegControl,0x01);
430 1 }
431
432
433
434 uchar M500PcdReset(void) //复位RC500
435 {
436 1 char idata status = MI_OK;
437 1 unsigned int idata timecnt=0;
438 1 RC500RST = 0;
439 1 delay_1ms(25);
440 1 RC500RST = 1;
441 1 delay_50us(50);
442 1 RC500RST = 0;
443 1 delay_50us(50);
444 1 timecnt=1000;
445 1 while ((ReadIO(RegCommand) & 0x3F)&&timecnt--);
446 1 if(!timecnt)
447 1 {
448 2 status = MI_RESETERR;
449 2 }
450 1 if (status == MI_OK)
451 1 {
452 2 // WriteIO(RegPage,0x80);
453 2 if (ReadIO(RegCommand) != 0x00)
454 2 {
455 3 status = MI_INTERFACEERR;
456 3 }
457 2 }
458 1 return status;
459 1 }
460
461 uchar M500PcdRfReset(unsigned char ms) //复位射频信号
462 {
463 1 char idata status = MI_OK;
464 1
465 1 if(ms)
466 1 {
467 2 ClearBitMask(RegTxControl,0x03);
468 2 delay_1ms(2);
469 2 SetBitMask(RegTxControl,0x03);
470 2 }
471 1 else
472 1 ClearBitMask(RegTxControl,0x03);
473 1
474 1 return status;
475 1 }
476 uchar M500PcdConfig(void) //RC500寄存器恢复初始设置
477 {
478 1 char idata status;
479 1
480 1 if ((status = M500PcdReset()) == MI_OK)
481 1 {
482 2 WriteIO(RegClockQControl,0x0);
483 2 WriteIO(RegClockQControl,0x40);
484 2 delay_50us(2);
485 2 ClearBitMask(RegClockQControl,0x40);
486 2 WriteIO(RegBitPhase,0xAD);
487 2 WriteIO(RegRxThreshold,0xFF);
488 2 WriteIO(RegRxControl2,0x01);
489 2 WriteIO(RegFIFOLevel,0x1A);
C51 COMPILER V6.02 M500AUC 11/20/2007 16:53:51 PAGE 9
490 2 WriteIO(RegTimerControl,0x02);
491 2 WriteIO(RegIRqPinConfig,0x03);
492 2 M500PcdRfReset(1);
493 2 }
494 1 return status;
495 1 }
496
497
498
499
500 uchar M500PiccCommonRequest(unsigned char req_code) //卡片请求命令
501
502 {
503 1 char idata status = MI_OK;
504 1
505 1 M500PcdSetTmo(3); //6ms
506 1 WriteIO(RegChannelRedundancy,0x03);
507 1 ClearBitMask(RegControl,0x08);
508 1 WriteIO(RegBitFraming,0x07);
509 1 SetBitMask(RegTxControl,0x03);
510 1 ResetInfo(MInfo);
511 1 SerBuffer[0] = req_code;
512 1 MInfo.nBytesToSend = 1;
513 1 status = M500PcdCmd(
514 1 SerBuffer,
515 1 &MInfo);
516 1
517 1 if (status)
518 1 {
519 2 Len=0;
520 2 }
521 1 else
522 1 {
523 2 if (MInfo.nBitsReceived != 16)
524 2 {
525 3 Len=0;
526 3 status = MI_BITCOUNTERR;
527 3 }
528 2 else
529 2 {
530 3 status = MI_OK;
531 3 for(ramlen=0;ramlen<2;ramlen++)
532 3 toPpc(ramlen,SerBuffer[ramlen]);
533 3 }
534 2 }
535 1 return status;
536 1 }
537
538 uchar M500PiccActive(void) //卡片激活命令
539 {
540 1 char idata status = MI_OK;
541 1
542 1 M500PcdSetTmo(3); //6ms
543 1 ResetInfo(MInfo);
544 1 SerBuffer[0] = 0xe0;
545 1 SerBuffer[1] = 0x50;
546 1 MInfo.nBytesToSend = 2;
547 1 status = M500PcdCmd(
548 1 SerBuffer,
549 1 &MInfo);
550 1
551 1 if (status)
C51 COMPILER V6.02 M500AUC 11/20/2007 16:53:51 PAGE 10
552 1 {
553 2 Len=0;
554 2 }
555 1 else
556 1 {
557 2 if (MInfo.nBitsReceived == 0)
558 2 {
559 3 Len=0;
560 3 status = MI_BITCOUNTERR;
561 3 }
562 2 else
563 2 {
564 3 status = MI_OK;
565 3 for(ramlen=0;ramlen<MInfo.nBytesReceived;ramlen++)
566 3 toPpc(ramlen,SerBuffer[ramlen]);
567 3
568 3 }
569 2 }
570 1 block_num=0;
571 1 return status;
572 1 }
573
574 uchar Send_MF(void) //向卡片直接发送数据SerBuffer 长度=Len
575 {
576 1
577 1 char idata status = MI_OK;
578 1 M500PcdSetTmo(3);
579 1 ResetInfo(MInfo);
580 1 if(block_num)
581 1 if((pcb&0xc0)==0)
582 1 pcb|=0x01;
583 1 SerBuffer[0]=pcb;
584 1 MInfo.nBytesToSend = Len+1;
585 1 if (SerBuffer[2]==0x0e) tt0=10;
586 1 else tt0=1;
587 1 status = M500PcdCmd(
588 1 SerBuffer,
589 1 &MInfo);
590 1
591 1 if (status)
592 1 {
593 2 MInfo.nBytesReceived=1;
594 2 Len=1;
595 2 return status;
596 2 }
597 1 else
598 1 {
599 2 if (MInfo.nBitsReceived == 0)
600 2 {
601 3 Len = 0;
602 3 return 0x1;
603 3 }
604 2 else
605 2 {
606 3 status = MI_OK;
607 3
608 3 }
609 2 }
610 1 return 0;
611 1 }
612
613 uchar M500PiccCascAnticoll (unsigned char select_code,
C51 COMPILER V6.02 M500AUC 11/20/2007 16:53:51 PAGE 11
614 unsigned char bcnt) //反冲突命令
615 {
616 1 char idata status = MI_OK;
617 1
618 1 char idata nbytes = 0;
619 1 char idata nbits = 0;
620 1 char idata complete = 0;
621 1 char idata i = 0;
622 1 char idata byteOffset = 0;
623 1
624 1 // dummy byte for snr shift
625 1
626 1 //************* Initialisation ******************************
627 1 M500PcdSetTmo(106);
628 1
629 1
630 1 WriteIO(RegDecoderControl,0x28); // ZeroAfterColl aktivieren
631 1 ClearBitMask(RegControl,0x08); // disable crypto 1 unit
632 1
633 1 //************** Anticollision Loop ***************************
634 1 complete = 0;
635 1 // bcnt = 0; // no part of the snr is known
636 1 while (!complete && (status == MI_OK) )
637 1 {
638 2 ResetInfo(MInfo);
639 2 WriteIO(RegChannelRedundancy,0x03); // RxCRC and TxCRC disable, parity enable
640 2 nbits = bcnt % 8; // remaining number of bits
641 2
642 2
643 2 SerBuffer[0] = select_code;
644 2 SerBuffer[1] = 0x20 + ((bcnt/8) << 4) + nbits; //number of bytes send
645 2
646 2
647 2 MInfo.nBytesToSend = 2 ;
648 2
649 2 status = M500PcdCmd(
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -