📄 m500aucend.lst
字号:
441 break;
442 default:
443 status = MI_UNKNOWN_COMMAND;
444 }
445 if (status == MI_OK)
446 {
447 irqEn |= 0x20;
448 waitFor |= 0x20;
449 timecnt=1000;
450 WriteIO(RegInterruptEn,irqEn | 0x80);
451 WriteIO(RegCommand,cmd);
452 while (!(MpIsrInfo->irqSource & waitFor||!(timecnt--)));
453 WriteIO(RegInterruptEn,0x7F);
454 WriteIO(RegInterruptRq,0x7F);
455 SetBitMask(RegControl,0x04);
456 WriteIO(RegCommand,PCD_IDLE);
457 if (!(MpIsrInfo->irqSource & waitFor))
458 {
459 status = MI_ACCESSTIMEOUT;
460 }
461 else
462 {
463 status = MpIsrInfo->status;
464 }
465 if (status == MI_OK)
466 {
467 if (tmpStatus = (ReadIO(RegErrorFlag) & 0x17))
468 {
469 if (tmpStatus & 0x01)
470 {
471 info->collPos = ReadIO(RegCollPos);
472 status = MI_COLLERR;
473 }
474 else
475 {
476 info->collPos = 0;
477 if (tmpStatus & 0x02)
478 {
479 status = MI_PARITYERR;
480 }
481 }
482 if (tmpStatus & 0x04)
483 {
484 status = MI_FRAMINGERR;
485 }
486 if (tmpStatus & 0x10)
487 {
488 FlushFIFO();
489 status = MI_OVFLERR;
490 }
491 if (tmpStatus & 0x08)
492 {
493 status = MI_CRCERR;
494 }
495 if (status == MI_OK)
496 status = MI_NY_IMPLEMENTED;
497 }
498 if (cmd == PCD_TRANSCEIVE)
499 {
500 lastBits = ReadIO(RegSecondaryStatus) & 0x07;
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 11
501 if (lastBits)
502 info->nBitsReceived += (info->nBytesReceived-1) * 8 + lastBits;
503 else
504 info->nBitsReceived += info->nBytesReceived * 8;
505 }
506 }
507 else
508 {
509 info->collPos = 0x00;
510 }
511 }
512 MpIsrInfo = 0;
513 MpIsrOut = 0;
514 return status;
515 }
516
517 ///////////////////////////////////////////////////////////////////////
518 // 置一个bit
519 ///////////////////////////////////////////////////////////////////////
520 char SetBitMask(unsigned char reg,unsigned char mask)
521 {
522 char idata tmp = 0x00;
523
524 tmp = ReadIO(reg);
525 WriteIO(reg,tmp | mask); // set bit mask
526 return 0x00;
527 }
528
529 ///////////////////////////////////////////////////////////////////////
530 // 清一个bit
531 ///////////////////////////////////////////////////////////////////////
532 char ClearBitMask(unsigned char reg,unsigned char mask)
533 {
534 char idata tmp = 0x00;
535
536 tmp = ReadIO(reg);
537 WriteIO(reg,tmp & ~mask); // clear bit mask
538 return 0x00;
539 }
540
541 ///////////////////////////////////////////////////////////////////////
542 ///////////////////////////////////////////////////////////////////////
543 void FlushFIFO(void)
544 {
545 SetBitMask(RegControl,0x01);
546 }
547
548 ///////////////////////////////////////////////////////////////////////
549 // Value format operations for Mifare Standard card ICs
550 ///////////////////////////////////////////////////////////////////////
551 char M500PiccValue(unsigned char dd_mode,
552 unsigned char addr,
553 unsigned char *value,
554 unsigned char trans_addr)
555 {
556 char status = MI_OK;
557
558 M500PcdSetTmo(1);
559 ResetInfo(MInfo);
560 SerBuffer[0] = dd_mode;
561 SerBuffer[1] = addr;
562 MInfo.nBytesToSend = 2;
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 12
563 status = M500PcdCmd(PCD_TRANSCEIVE,
564 SerBuffer,
565 &MInfo);
566
567 if (status != MI_NOTAGERR)
568 {
569 if (MInfo.nBitsReceived != 4)
570 {
571 status = MI_BITCOUNTERR;
572 }
573 else
574 {
575 SerBuffer[0] &= 0x0f;
576 switch(SerBuffer[0])
577 {
578 case 0x00:
579 status = MI_NOTAUTHERR;
580 break;
581 case 0x0a:
582 status = MI_OK;
583 break;
584 case 0x01:
585 status = MI_VALERR;
586 break;
587 default:
588 status = MI_CODEERR;
589 break;
590 }
591 }
592 }
593
594 if ( status == MI_OK)
595 {
596 M500PcdSetTmo(3);
597 ResetInfo(MInfo);
598 memcpy(SerBuffer,value,4);
599 MInfo.nBytesToSend = 4;
600 status = M500PcdCmd(PCD_TRANSCEIVE,
601 SerBuffer,
602 &MInfo);
603
604 if (status == MI_OK)
605 {
606 if (MInfo.nBitsReceived != 4)
607 {
608 status = MI_BITCOUNTERR;
609 }
610 else
611 {
612 SerBuffer[0] &= 0x0f;
613 switch(SerBuffer[0])
614 {
615 case 0x00:
616 status = MI_NOTAUTHERR;
617 break;
618 case 0x01:
619 status = MI_VALERR;
620 break;
621 default:
622 status = MI_CODEERR;
623 break;
624 }
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 13
625 }
626 }
627 else
628 {
629 if (status == MI_NOTAGERR )
630 status = MI_OK;
631 }
632 }
633 if (status == MI_OK)
634 {
635 ResetInfo(MInfo);
636 SerBuffer[0] = PICC_TRANSFER;
637 SerBuffer[1] = trans_addr;
638 MInfo.nBytesToSend = 2;
639 status = M500PcdCmd(PCD_TRANSCEIVE,
640 SerBuffer,
641 &MInfo);
642 if (status != MI_NOTAGERR)
643 {
644 if (MInfo.nBitsReceived != 4)
645 {
646 status = MI_BITCOUNTERR;
647 }
648 else
649 {
650 SerBuffer[0] &= 0x0f;
651 switch(SerBuffer[0])
652 {
653 case 0x00:
654 status = MI_NOTAUTHERR;
655 break;
656 case 0x0a:
657 status = MI_OK;
658 break;
659 case 0x01:
660 status = MI_VALERR;
661 break;
662 default:
663 status = MI_CODEERR;
664 break;
665 }
666 }
667 }
668 }
669 return status;
670 }
671
672 ///////////////////////////////////////////////////////////////////////
673 // Set card in HALT-state
674 // 终止卡的操作
675 ///////////////////////////////////////////////////////////////////////
676 char M500PiccHalt(void)
677 {
678 char idata status = MI_CODEERR;
679
680 // ************* Cmd Sequence **********************************
681 ResetInfo(MInfo);
682 SerBuffer[0] = PICC_HALT ; // Halt command code
683 SerBuffer[1] = 0x00; // dummy address
684 MInfo.nBytesToSend = 2;
685 status = M500PcdCmd(PCD_TRANSCEIVE,
686 SerBuffer,
C51 COMPILER V7.03 M500AUCEND 05/07/2004 12:23:37 PAGE 14
687 &MInfo);
688 if (status)
689 {
690 // timeout error ==> no NAK received ==> OK
691 if (status == MI_NOTAGERR || status == MI_ACCESSTIMEOUT)
692 {
693 status = MI_OK;
694 }
695 }
696 //reset command register - no response from tag
697 WriteIO(RegCommand,PCD_IDLE);
698 return status;
699 }
700
701 ///////////////////////////////////////////////////////////////////////
702 // Reset the MF RC500
703 ///////////////////////////////////////////////////////////////////////
704 char M500PcdReset(void)
705 {
706 char idata status = MI_OK;
707 unsigned int idata timecnt=0;
708
709 RC500RST = 0;
710 delay_1ms(25);
711 RC500RST = 1;
712 delay_50us(200);
713 RC500RST = 0;
714 delay_50us(50);
715 timecnt=1000;
716 while ((ReadIO(RegCommand) & 0x3F) && timecnt--);
717 if(!timecnt)
718 {
719 status = MI_RESETERR;
720 }
721 if (status == MI_OK)
722 {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -