?? m500auc.lst
字號:
584 1 while (_1ms--)
585 1 {
586 2 delay_50us(20);
587 2 }
588 1 #endif
589 1 }
590
591 ///////////////////////////////////////////////////////////////////////
592 // Delay 10ms
593 ///////////////////////////////////////////////////////////////////////
594 void delay_10ms(unsigned int _10ms)
595 {
596 1 #ifndef NO_TIMER2
RCAP2LH = RCAP2_10ms;
T2LH = RCAP2_10ms;
TR2 = TRUE;
while (_10ms--)
{
while (!TF2);
TF2 = FALSE;
}
TR2 = FALSE;
#else
608 1 while (_10ms--)
609 1 {
610 2 delay_50us(19);
611 2 if (CmdValid)
612 2 return;
613 2 delay_50us(20);
C51 COMPILER V7.50 M500AUC 06/14/2005 11:34:17 PAGE 11
614 2 if (CmdValid)
615 2 return;
616 2 delay_50us(20);
617 2 if (CmdValid)
618 2 return;
619 2 delay_50us(20);
620 2 if (CmdValid)
621 2 return;
622 2 delay_50us(20);
623 2 if (CmdValid )
624 2 return;
625 2 delay_50us(20);
626 2 if (CmdValid)
627 2 return;
628 2 delay_50us(20);
629 2 if (CmdValid)
630 2 return;
631 2 delay_50us(20);
632 2 if (CmdValid)
633 2 return;
634 2 delay_50us(20);
635 2 if (CmdValid)
636 2 return;
637 2 delay_50us(19);
638 2 if (CmdValid)
639 2 return;
640 2 }
641 1 #endif
642 1 }
643
644 ///////////////////////////////////////////////////////////////////////
645 ///////////////////////////////////////////////////////////////////////
646 void RC500ISR (void) interrupt 0 using 1
647 {
648 1 static unsigned char idata irqBits;
649 1 static unsigned char idata irqMask;
650 1 static unsigned char idata nbytes;
651 1 static unsigned char idata cnt;
652 1
653 1 IE0 = 0;
654 1 WriteRawIO(0,0x80);
655 1 if (MpIsrInfo && MpIsrOut)
656 1 {
657 2 while( ReadRawIO(RegPrimaryStatus) & 0x08)
658 2 {
659 3 irqMask = ReadRawIO(RegInterruptEn);
660 3 irqBits = ReadRawIO(RegInterruptRq) & irqMask;
661 3 MpIsrInfo->irqSource |= irqBits;
662 3 if (irqBits & 0x01)
663 3 {
664 4 nbytes = 64 - ReadRawIO(RegFIFOLength);
665 4 if ((MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent) <= nbytes)
666 4 {
667 5 nbytes = MpIsrInfo->nBytesToSend - MpIsrInfo->nBytesSent;
668 5 WriteRawIO(RegInterruptEn,0x01);
669 5 }
670 4 for ( cnt = 0;cnt < nbytes;cnt++)
671 4 {
672 5 WriteRawIO(RegFIFOData,MpIsrOut[MpIsrInfo->nBytesSent]);
673 5 MpIsrInfo->nBytesSent++;
674 5 }
675 4 WriteRawIO(RegInterruptRq,0x01);
C51 COMPILER V7.50 M500AUC 06/14/2005 11:34:17 PAGE 12
676 4 }
677 3 if (irqBits & 0x10)
678 3 {
679 4 WriteRawIO(RegInterruptRq,0x10);
680 4 WriteRawIO(RegInterruptEn,0x82);
681 4 if (MpIsrInfo->cmd == PICC_ANTICOLL1)
682 4 {
683 5 WriteIO(RegChannelRedundancy,0x02);
684 5 WriteRawIO(0,0x80);
685 5 }
686 4 }
687 3 if (irqBits & 0x0E)
688 3 {
689 4 nbytes = ReadRawIO(RegFIFOLength);
690 4 for ( cnt = 0; cnt < nbytes; cnt++)
691 4 {
692 5 MpIsrOut[MpIsrInfo->nBytesReceived] = ReadRawIO(RegFIFOData);
693 5 MpIsrInfo->nBytesReceived++;
694 5 }
695 4 WriteRawIO(RegInterruptRq,0x0A & irqBits);
696 4 }
697 3 if (irqBits & 0x04)
698 3 {
699 4 WriteRawIO(RegInterruptEn,0x20);
700 4 WriteRawIO(RegInterruptRq,0x20);
701 4 irqBits &= ~0x20;
702 4 MpIsrInfo->irqSource &= ~0x20;
703 4 WriteRawIO(RegInterruptRq,0x04);
704 4 }
705 3 if (irqBits & 0x20)
706 3 {
707 4 WriteRawIO(RegInterruptRq,0x20);
708 4 MpIsrInfo->status = MI_NOTAGERR;
709 4 }
710 3 }
711 2 }
712 1 }
713
714 ///////////////////////////////////////////////////////////////////////
715 // 接收和發送中斷
716 ///////////////////////////////////////////////////////////////////////
717 void isr_UART(void) interrupt 4 using 1
718 {
719 1 unsigned char len, i;
720 1 unsigned int j=0;
721 1
722 1 if(RI)
723 1 {
724 2 len=SBUF;
725 2 RI=0;
726 2 for(i=0;i<len;i++)
727 2 {
728 3 while(!RI)
729 3 {
730 4 j++;
731 4 if(j>1000)
732 4 {
733 5 break;
734 5 }
735 4 }
736 3 if(j<1000)
737 3 {
C51 COMPILER V7.50 M500AUC 06/14/2005 11:34:17 PAGE 13
738 4 RevBuffer[i]=SBUF;
739 4 RI=0;
740 4 j=0;
741 4 }
742 3 else
743 3 {
744 4 break;
745 4 }
746 3 }
747 2 if(i==len)
748 2 {
749 3 REN=0;
750 3 CmdValid=1;
751 3 }
752 2 }
753 1 else if(!RI && TI)
754 1 {
755 2 TI=0;
756 2 len=RevBuffer[0];
757 2 for(i=1;i<len+1;i++)
758 2 {
759 3 SBUF=RevBuffer[i];
760 3 while(!TI);
761 3 TI=0;
762 3 }
763 2 REN=1;
764 2 }
765 1 }
766
767 ///////////////////////////////////////////////////////////////////////
768 // MF RC500 Config
769 ///////////////////////////////////////////////////////////////////////
770 char MfConfig(void)
771 {
772 1 char status=MI_OK;
773 1
774 1 M500PcdConfig();
775 1 M500PcdMfOutSelect(2);
776 1 return status;
777 1 }
778
779 ///////////////////////////////////////////////////////////////////////
780 // 系統初始化
781 ///////////////////////////////////////////////////////////////////////
782 void init(void)
783 {
784 1 RC500RST=0;
785 1 ET2 = 0;
786 1 T2CON = 0x04;
787 1 PCON = 0x80;
788 1 SCON = 0x70;
789 1 TMOD = 0x21; //TMOD = 0x22;
790 1
791 1 TH1 = BAUD_9600;
792 1 TL1 = TH1;
793 1 TR1 = TRUE; // 波特率發生器
794 1
795 1 TH0 = 0x60;
796 1 TL0 = 0x60;
797 1 TR0 = 0;
798 1
799 1 ET0=0;
C51 COMPILER V7.50 M500AUC 06/14/2005 11:34:17 PAGE 14
800 1 ET1=0;
801 1 EA=1;
802 1 EX0=1;
803 1 IT0 = 1;
804 1 TR2=0;
805 1 ES = TRUE;
806 1 CmdValid=0;
807 1 // AUXR=0x02;
808 1
809 1 SPEAKER=0; LED=0;
810 1 delay_10ms(30);
811 1 SPEAKER=1;
812 1 LED=1;
813 1
814 1 MfConfig();
815 1 }
816
817 ///////////////////////////////////////////////////////////////////////
818 // IC卡處理函數
819 ///////////////////////////////////////////////////////////////////////
820 void cmd_execution(void)
821 {
822 1 unsigned char status;
823 1 unsigned char Connect_Status=00;
824 1 //尋找卡
825 1 RevBuffer[1]=0x26;//,26為RegMfOutSele
826 1 status=M500PiccCommonRequest(RevBuffer[1],&RevBuffer[2]);
827 1 if(status==0)
828 1 {
829 2 // 防沖突 讀卡的系列號 MLastSelectedSnr
830 2 status = M500PiccCascAnticoll(0,&RevBuffer[2]);
831 2 if(status==0)
832 2 {
833 3 LED=0;
834 3 SPEAKER=0;
835 3 RevBuffer[0]=7;
836 3 RevBuffer[1]=0xFE;
837 3 RevBuffer[7]=0x7F;
838 3 CALL_isr_UART(); //觸發串口中斷
839 3 M500PiccHalt(); //終止IC卡操
840 3 delay_10ms(30);
841 3 SPEAKER=1;
842 3 LED=1;
843 3 delay_10ms(30);
844 3
845 3 }
846 2 }
847 1 }
848
849 ///////////////////////////////////////////////////////////////////////
850 // 主函數
851 ///////////////////////////////////////////////////////////////////////
852
853 void main(void)
854 {
855 1 init();
856 1 while(1)
857 1 {
858 2 cmd_execution(); // 進入IC卡處理程序
859 2 }
860 1 }
861
C51 COMPILER V7.50 M500AUC 06/14/2005 11:34:17 PAGE 15
862
MODULE INFORMATION: STATIC OVERLAYABLE
CODE SIZE = 2781 ----
CONSTANT SIZE = 6 ----
XDATA SIZE = ---- ----
PDATA SIZE = ---- ----
DATA SIZE = 27 15
IDATA SIZE = 47 28
BIT SIZE = 1 ----
END OF MODULE INFORMATION.
C51 COMPILATION COMPLETE. 0 WARNING(S), 0 ERROR(S)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -