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

📄 main.lst

📁 射频卡读卡头的程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V4.01,  MAIN                                                                  29/08/06  08:02:00  PAGE 1   


DOS C51 COMPILER V4.01, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN F:\1\MAIN.OBJ
COMPILER INVOKED BY: C:\COMP51\C51.EXE F:\1\MAIN.C DB SB OE

stmt level    source

   1          /****************************************************************************
   2          *                                                                           *
   3          * File:         MAIN.C                                                      *
   4          *                                                                           *
   5          * Version:      V3.2                                       		            *
   6          *                                                                           *
   7          * Created:      2003/10/11                                                  *
   8          * Last Change:  2005/06/04                                                   *
   9          * 增加看门狗控制 防止CPU 死机                                               *
  10          * Author:       DavidQi                                                     *
  11          *                                                                           *
  12          * Compiler:     KEIL C51 V6.23A                                             *
  13          *                                                                           *
  14          * Description:  输出 M1序列号                                               *
  15          *                                                                           *
  16          ****************************************************************************/
  17          #pragma large
  18          #define __SRC
  19          #include "main.h"
  20          #undef  __SRC
  21          
  22          #include <string.h>
  23          #include <intrins.h>
  24          #include <stdio.h>
  25          
  26          #include "m500a.h"
  27          #include "cpu.h"
  28          #include "rdio.h"
  29          
  30          #define MIS_CHK_OK              (0)
  31          #define MIS_CHK_FAILED          (-1)
  32          #define MIS_CHK_COMPERR         (-2)
  33          
  34          // Function: mifs_request
  35          #define IDLE                    0x00
  36          #define ALL                     0x01
  37          
  38          
  39          // PC Debug Data: 02 30 31 32 03 33     checksum =33 (30^31^32)
  40          // Release Number of the Firmware
  41          uchar code SW_Rel[] = "\n\r MFRC500 V1.0 8.03.2003 \n\r";
  42          uchar code ms[4][2] = {{0x0,0x0},{0x0,0x0},{0x0,0x0},{0x0,0x0}};
  43          
  44          // Serial Number of the MFRC500
  45          //uchar Snr_RC500[4];
  46          uchar xdata Snr_RC500[4];
  47          //static uint Crc;
  48          
  49          // Local Prototypes
  50          void init(void);
  51          void cmd_execution(void);
  52          
  53          // Interrupt Service Routines
  54          void isr_timer0(void);
  55          void isr_UART(void);
  56          
  57          //uchar card_snr[4];
  58          uchar  xdata card_snr[4];
  59          char   xdata ErrNum;
C51 COMPILER V4.01,  MAIN                                                                  29/08/06  08:02:00  PAGE 2   

  60          
  61          
  62          //cqbq
  63          uchar idata cardnum[4];    //无符号字符数组变量cardnum[4]被定义为idata 存贮类型
  64          uchar xdata nums;
  65          
  66          unsigned char code CmdData_1[]={0x7f,0x40,0x05,0x0,0x0,0x0,0x0};
  67          
  68          unsigned char code CmdData_2[]={0x7f,0x42,0x08,0x0,0x0,0x0,0x0,0x0};
  69          
  70          uchar xdata SectorNum, BlockNum,CommandNum,Key[6],CardData[16],KeyData[6];
  71          
  72          uchar xdata CardSnrNum[6];
  73          
  74          uchar xdata SnrErr;
  75          
  76          uchar idata ComeCard = 0,GoCard = 0;ChkSum1 = 0;
  77          uchar idata DetCardCnt=0;
  78          bit   bdata SendCardSnrFlag;
  79          
  80          //cqbq
  81          bit CopyCardNum ( void )
  82          {
  83   1           bit flag_num=1;      //因为默认存贮类型为XDATA,所以表示为 位变量flag_num
  84   1                                // 被定义为 XDATA存贮类型
  85   1           uchar idata i=0;
  86   1           uchar idata *pnt0 = &cardnum;  //无字符指针变量pnt0被定义为 idata 存贮类型,并将数组
  87   1                                          // cardnum 的首地址赋给指针变量pnt0,而不是(*pnt0)
  88   1           uchar xdata *pnt1 = &SerBuffer[3];
  89   1      
  90   1           if (SerBuffer[3]==SerBuffer[4] && SerBuffer[5] == SerBuffer[6] && SerBuffer[3] == SerBuffer[5])
  91   1              return flag_num;
  92   1      
  93   1           for (i=0;i<4;i++)
  94   1           {
  95   2               if (*pnt0==*pnt1)
  96   2               {
  97   3                   pnt0++;
  98   3                   pnt1++;
  99   3               }
 100   2               else
 101   2               {
 102   3                   nums++;
 103   3                   if (nums>10)
 104   3                      flag_num=0;
 105   3               }
 106   2               break;
 107   2           }
 108   1      
 109   1           if (nums>10)
 110   1           {
 111   2              pnt0=&cardnum;
 112   2              pnt1=&SerBuffer[3];
 113   2              for (i=0;i<4;i++)
 114   2              {
 115   3                  *pnt0++ = *pnt1++;
 116   3              }
 117   2              nums=0;
 118   2           }
 119   1           return ( flag_num );
 120   1      }
 121          
 122          void main (void)
 123          {
 124   1        init();
 125   1      
C51 COMPILER V4.01,  MAIN                                                                  29/08/06  08:02:00  PAGE 3   

 126   1        test();
 127   1      
 128   1        #ifdef sst89e554
 129   1        WDTC = WDTC|0x01;     //Start watchdog timer
 130   1        #endif
 131   1        
 132   1        #ifdef sm8958  
                //WDTC_CLR = 1;        // refresh watchdog timer 
                clrWDT();
                
                #endif
 137   1      
 138   1        M500PcdConfig();  	// Initialise the RC500
 139   1      	                    // must be call in the initialization
 140   1      
 141   1      //  RC500 E2PROM  0x00--0x0f Product Information Field
 142   1      //                0x08--0x0b  Product Serial Number
 143   1      
 144   1        PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it
 145   1      
 146   1        RingOn();
 147   1      
 148   1        SendCardSnrFlag = 1;
 149   1      
 150   1        while(1)
 151   1        {
 152   2          init();
 153   2          M500PcdConfig();
 154   2      
 155   2          DetCardCnt = 10;
 156   2          ComeCard = 0;
 157   2      
 158   2          while(DetCardCnt!=0|ComeCard==3)
 159   2          {
 160   3           SerBuffer[1] = 0x40;
 161   3           cmd_execution();
 162   3           
 163   3            //cqbq
 164   3              if ( AccOk )
 165   3              {
 166   4                 SerBuffer[1] = 0x42;
 167   4                 SerBuffer[3] = 0;
 168   4                 cmd_execution();
 169   4      
 170   4                 if ( AccOk )
 171   4                 {
 172   5                    if ( !CopyCardNum() )
 173   5                    {
 174   6                       AccOk=0;
 175   6                       P1_6=0;
 176   6                       GoCard=0;
 177   6                       ComeCard=0;
 178   6      
 179   6                    delay_10ms (5);
 180   6                    }
 181   5                  }
 182   4              }
 183   3              // 
 184   3      
 185   3           if(AccOk )
 186   3           {
 187   4              ComeCard++;
 188   4              if(ComeCard == 3)
 189   4              {
 190   5                P1_6 = 1;
 191   5               // ComeCard = 0;
C51 COMPILER V4.01,  MAIN                                                                  29/08/06  08:02:00  PAGE 4   

 192   5                break;
 193   5              }
 194   4              else
 195   4              {
 196   5                 if(ComeCard > 3)
 197   5                 {
 198   6                    ComeCard = 3;
 199   6                    P1_6 = 1;
 200   6                 }
 201   5              }
 202   4              AccOk = FALSE ;
 203   4              GoCard = 0;
 204   4           }
 205   3           else
 206   3           {
 207   4               GoCard++;
 208   4               if(GoCard == 3)
 209   4               {
 210   5                 P1_6 = 0;
 211   5                 GoCard = 0;
 212   5               }
 213   4               ComeCard = 0;
 214   4      
 215   4               SendCardSnrFlag = 1;
 216   4      
 217   4           }
 218   3      
 219   3           if(DetCardCnt != 0 )  DetCardCnt--;
 220   3      
 221   3           M500PcdConfig();
 222   3           //SerBuffer[1] = 0x45;
 223   3           //cmd_execution();
 224   3           //delay_10ms(5);
 225   3           #ifdef sst89e554
 226   3           WDTC = WDTC|0x02;  // refresh watchdog
 227   3           WDTD = 0x80;       // Reload timer
 228   3           #endif
 229   3           
 230   3           #ifdef sm8958  
                   //WDTC_CLR = 1;        // refresh watchdog timer
                	 clrWDT();       
                   #endif 
 234   3         }
 235   2      
 236   2          #ifdef sst89e554
 237   2          WDTC = WDTC|0x02;  // refresh watchdog
 238   2          WDTD = 0x80;       // Reload timer
 239   2          #endif
 240   2          
 241   2          #ifdef sm8958  
                   //WDTC_CLR = 1;        // refresh watchdog timer
                	 clrWDT();       
                   #endif 
 245   2      
 246   2          M500PcdConfig();
 247   2         // SerBuffer[1] = 0x45;
 248   2         // cmd_execution();
 249   2         // delay_10ms(5);
 250   2      
 251   2      // 检测是否有MIFARE卡在读头感应区,有卡将卡号发送到PC机
 252   2         /*
 253   2          while(!AccOk)
 254   2          {
 255   2            memcpy(SerBuffer,CmdData_1,7);
 256   2            cmd_execution();
 257   2      
C51 COMPILER V4.01,  MAIN                                                                  29/08/06  08:02:00  PAGE 5   

 258   2      	  AccOk = FALSE ;
 259   2      
 260   2            memcpy(SerBuffer,CmdData_2,8);
 261   2      
 262   2           // 命令码: 0x42:  执行 Anticoll 返回序列号
 263   2            cmd_execution();
 264   2      
 265   2           }
 266   2      
 267   2          AccOk = FALSE ;
 268   2      
 269   2          TransHexAsi(&SerBuffer[3],SendBuffer,4);//4字节卡序列号
 270   2      
 271   2          SendDataToPc(SendBuffer,8);//发送8字节ASCII码到PC
 272   2          */
 273   2          AccOk = FALSE ;
 274   2          //等待PC 发送命令
 275   2         // while(!FrameOk);
 276   2          //RingOn();
 277   2      
 278   2          //TransData(PcData,SerBuffer,DataLen);//SerBuffer: PC 与MCU交互数据缓冲区
 279   2      
 280   2          /*
 281   2           cmd_execution() 命令执行程序
 282   2           命令码:               命令功能:
 283   2           0x40:                  // PICC_REQALL
 284   2           0x41:                  // Request
 285   2           0x42:                  // Anticoll
 286   2           0x43:                  // Select
 287   2           0x44:                  // Authentication
 288   2           0x45:                  // Halt
 289   2      	 0x46:                  // Read
 290   2           0x47:                  // Write
 291   2      	 0x48:                  // Increment
 292   2           0x49:					// Decrement
 293   2           0x4A:					// Restore
 294   2      	 0x4B:					// Transfer
 295   2      	 0x4C:					// Load Key
 296   2           0x4D:					// comm check char
 297   2           0x4E:					// Reset
 298   2           0x4F:                 	// Get Info
 299   2           0x50:					// Set Control Bit
 300   2           0x51:					// Clr Control Bit
 301   2           0x52:                 	// Config
 302   2           0x53:					// Check Write
 303   2           0x54:					// Set Port
 304   2           0x55:					// Get Port

⌨️ 快捷键说明

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