main.lst
来自「学校水POS读卡程序」· LST 代码 · 共 1,499 行 · 第 1/5 页
LST
1,499 行
573 2 if (SerBuffer[MODE] == SER_BCC)
574 2 {
575 3 CheckByteCnt = BCC_CHECKBYTECNT;
576 3 }
577 2 else
578 2 {
579 3 CheckByteCnt = CRC_CHECKBYTECNT;
580 3 }
581 2 Status = MI_OK;
582 2 break;
583 2
584 2
585 2 case 0x4E: // Reset
586 2
587 2 M500PcdRfReset(SerBuffer[TIME]);
588 2 Status = MI_OK;
589 2 break;
590 2
591 2
592 2 case 0x4F: // Get Info
593 2
594 2 if ((len == 0) || (len == 1 && SerBuffer[MODE] == 1))
595 2 {
596 3 for (adr = INFO; adr < INFO_CNT + INFO; adr++)
597 3 {
598 4 SerBuffer[adr] = SW_Rel[adr-INFO];
599 4 }
600 3 SerBuffer[adr++] = ' ';
601 3 SerBuffer[adr++] = '0';
602 3 SerBuffer[adr++] = 'x';
603 3 SerBuffer[adr++] = xtoa_h(Snr_RC500[0]);
604 3 SerBuffer[adr++] = xtoa_l(Snr_RC500[0]);
605 3 SerBuffer[adr++] = xtoa_h(Snr_RC500[1]);
606 3 SerBuffer[adr++] = xtoa_l(Snr_RC500[1]);
607 3 SerBuffer[adr++] = xtoa_h(Snr_RC500[2]);
608 3 SerBuffer[adr++] = xtoa_l(Snr_RC500[2]);
609 3 SerBuffer[adr++] = xtoa_h(Snr_RC500[3]);
610 3 SerBuffer[adr++] = xtoa_l(Snr_RC500[3]);
611 3 SerBuffer[adr++] = '\0';
612 3
C51 COMPILER V6.23a MAIN 08/03/2004 08:47:24 PAGE 11
613 3 SerBuffer[LENGTH] = adr - INFO;
614 3 }
615 2 else
616 2 {
617 3 if (SerBuffer[MODE] == 2)
618 3 {
619 4 SerBuffer[INFO] = (uchar) Capt;
620 4 SerBuffer[INFO + 1] = (uchar)(Capt >> 8);
621 4 SerBuffer[INFO + 2] = BaudRate;
622 4 SerBuffer[INFO + 3] = DelayRate;
623 4 }
624 3 else
625 3 {
626 4 SerBuffer[INFO] = Snr_RC500[0];
627 4 SerBuffer[INFO + 1] = Snr_RC500[1];
628 4 SerBuffer[INFO + 2] = Snr_RC500[2];
629 4 SerBuffer[INFO + 3] = Snr_RC500[3];
630 4 }
631 3 SerBuffer[LENGTH] = 4;
632 3 }
633 2
634 2 Status = MI_OK;
635 2 break;
636 2
637 2
638 2 case 0x50: // Set Control Bit
639 2 if (SerBuffer[INFO]&0x01)
640 2 Status = MI_OK;
641 2 if (SerBuffer[INFO]&0x02)
642 2 Status = MI_OK;
643 2 if (SerBuffer[INFO]&0x04)
644 2 Status = MI_OK;
645 2
646 2 Status = MI_OK;
647 2 break;
648 2
649 2
650 2 case 0x51: // Clr Control Bit
651 2
652 2 Status = MI_OK;
653 2 break;
654 2
655 2
656 2 case 0x52: // Config
657 2
658 2 Status = M500PcdConfig();
659 2
660 2 #ifdef AUTODELAY
661 2 DelayRate = 0;
662 2 #endif
663 2 break;
664 2
665 2
666 2 case 0x53: // Check Write
667 2
668 2 Status = MIS_CHK_FAILED;
669 2
670 2 if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
671 2 {
672 3 if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
673 3 {
674 4 break;
C51 COMPILER V6.23a MAIN 08/03/2004 08:47:24 PAGE 12
675 4 }
676 3 }
677 2 if (M500PiccSelect(&SerBuffer[SERNR], &size) != MI_OK)
678 2 {
679 3 if (M500PiccRequest(PICC_REQALL, tt) != MI_OK)
680 3 {
681 4 break;
682 4 }
683 3 if (M500PiccSelect(&SerBuffer[SERNR], &size) != MI_OK)
684 3 {
685 4 break;
686 4 }
687 3 }
688 2 memcpy(card_snr,&SerBuffer[SERNR],4);
689 2 if(SerBuffer[AUTHMODE]&0X04) SerBuffer[AUTHMODE]=PICC_AUTHENT1B; // keyB
690 2 else SerBuffer[AUTHMODE]=PICC_AUTHENT1A; // keyA
691 2
692 2 //if (Status = M500PiccAuth(SerBuffer[AUTHMODE], card_snr,
693 2 // SerBuffer[ADRCHKWR]>>2, SerBuffer[ADRCHKWR]) != MI_OK)
694 2 if (Status = M500PiccAuthE2(SerBuffer[AUTHMODE], card_snr,
695 2 SerBuffer[ADRCHKWR]>>2, SerBuffer[ADRCHKWR]) != MI_OK)
696 2 {
697 3 break;
698 3 }
699 2
700 2 if (M500PiccRead(SerBuffer[ADRCHKWR], tmp) != MI_OK)
701 2 {
702 3 break;
703 3 }
704 2
705 2 if (memcmp(&SerBuffer[DATACHKWR], tmp, 16) != MI_OK)
706 2 {
707 3 Status = MIS_CHK_COMPERR;
708 3 }
709 2 else
710 2 {
711 3 Status = MIS_CHK_OK;
712 3 }
713 2 break;
714 2
715 2
716 2 case 0x54: // Set Port
717 2
718 2 P1 |= (SerBuffer[PORTBYTE]&0x0f); // set the desired port pin
719 2 P1 &= (SerBuffer[PORTBYTE]|0xf0); // clear the desired port pin
720 2 if (SerBuffer[PORTBYTE]&0x10)
721 2 LED = ON;
722 2 else
723 2 LED = OFF;
724 2 Status = MI_OK;
725 2 break;
726 2
727 2
728 2 case 0x55: // Get Port
729 2
730 2 SerBuffer[PORTBYTE] = P1&0xf;
731 2 SerBuffer[LENGTH] = 1;
732 2 Status = MI_OK;
733 2 break;
734 2
735 2 case 0x56: // Authentication2
736 2
C51 COMPILER V6.23a MAIN 08/03/2004 08:47:24 PAGE 13
737 2 if(SerBuffer[MODE]&0X04) SerBuffer[MODE]=PICC_AUTHENT1B; // keyB
738 2 else SerBuffer[MODE]=PICC_AUTHENT1A; // keyA
739 2
740 2 //Status = M500PiccAuth(SerBuffer[MODE], card_snr,
741 2 // SerBuffer[SECNR], SerBuffer[AUTHADD]);
742 2 Status = M500PiccAuthE2(SerBuffer[MODE], card_snr,
743 2 SerBuffer[SECNR], SerBuffer[AUTHADD]);
744 2 break;
745 2
746 2
747 2 case 0x57: // Decrement+Transfer
748 2
749 2 Status = M500PiccValue(PICC_DECREMENT, SerBuffer[ADR], &SerBuffer[VALUE], SerBuffer[ADR]);
750 2 break;
751 2
752 2 default:
753 2
754 2 Status = MI_NY_IMPLEMENTED;
755 2 break;
756 2
757 2
758 2 } // end switch (Command)
759 1
760 1 SerBuffer[STATUS] = ~Status+1;
761 1
762 1 if (cmd < 0x48 || cmd > 0x4A)
763 1 {
764 2 EnableTransferCmd = FALSE;
765 2 }
766 1 else
767 1 {
768 2 EnableTransferCmd = TRUE;
769 2 }
770 1 }
771
772
773 /****************************************************************************
774 * *
775 * Function: auto_baud *
776 * *
777 * Input: - *
778 * Output: - *
779 * *
780 * Description: *
781 * *
782 * Mi醫 die Zeitspanne zwischen Start- und Stopbit des ersten empfangenen *
783 * Zeichens (STX) und ermittelt daraus die Baudrate. *
784 * *
785 ****************************************************************************/
786
787 void auto_baud (void)
788 {
789 1 //int temp;
790 1
791 1 if (AutoBaud && !RXD) // If autobaud is enable and RXD pin is low
792 1 {
793 2 TR0 = TRUE; // Start timer0
794 2
795 2 do
796 2 {
797 3 if (RXD) // When RXD pin is high
798 3 {
C51 COMPILER V6.23a MAIN 08/03/2004 08:47:24 PAGE 14
799 4 Capt_L = TL0;
800 4 Capt_H = TH0;
801 4
802 4 do
803 4 {
804 5 if (!RXD)
805 5 {
806 6 break;
807 6 }
808 5 } while (!TF0);
809 4 }
810 3 } while (!TF0);
811 2
812 2 TR0 = FALSE;
813 2 TF0 = FALSE;
814 2
815 2 Capt = ((uint)Capt_H << 5) | ((uint)Capt_L & 0x001F);
816 2
817 2 for (BaudRate = BAUD_CNT; BaudRate >= 0; BaudRate--)
818 2 {
819 3 if (Capt >= CmpTable[BaudRate])
820 3 {
821 4 break;
822 4 }
823 3 }
824 2
825 2 if (BaudRate < 0 || BaudRate == BAUD_CNT) // Error baud count
826 2 {
827 3 TH0 = 0;
828 3 TL0 = 0;
829 3 Capt_L = 0;
830 3 Capt_H = 0;
831 3 return;
832 3 }
833 2
834 2 TMOD = 0x21; // Timer 0, mode 1, 16-bit counter
835 2 TH1 = BaudRateTable[BaudRate];
836 2 TL1 = TH1;
837 2 TR1 = TRUE;
838 2
839 2 TH0 = 0xE0;
840 2 TL0 = 0;
841 2 TR0 = TRUE;
842 2 while (!TF0); // Wait 4.4 ms
843 2 TR0 = FALSE;
844 2 TF0 = FALSE;
845 2 ET0 = TRUE;
846 2
847 2 AutoBaud = FALSE; // Baudrate had been choose, disable Autobaud
848 2
849 2 SBUF = NAK;
850 2 while (!TI);
851 2 TI = FALSE;
852 2 RI = FALSE;
853 2 ES = TRUE;
854 2 }
855 1 }
856
857 #pragma noaregs
858
859 /****************************************************************************
860 * *
C51 COMPILER V6.23a MAIN 08/03/2004 08:47:24 PAGE 15
861 * Function: delay_50us *
862 * *
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?