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

📄 main.lst

📁 学校水POS读卡程序
💻 LST
📖 第 1 页 / 共 5 页
字号:
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 1   


C51 COMPILER V6.23a, COMPILATION OF MODULE MAIN
OBJECT MODULE PLACED IN main.OBJ
COMPILER INVOKED BY: D:\Keil\C51\BIN\C51.EXE main.c LARGE OPTIMIZE(2,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          /****************************************************************************
   2          *                                                                           *
   3          * File:         MAIN.C                                                      *
   4          *                                                                           *
   5          * Version:      V1.0                                                                *
   6          *                                                                           *
   7          * Created:      2003/10/11                                                  *
   8          * Last Change:  2004/6/20                                                  *
   9          *                                                                           *
  10          * Author:       DavidQi                                                     *
  11          *                                                                           *
  12          * Compiler:     KEIL C51 V6.23A                                             *
  13          *                                                                           *
  14          * Description:                                                              *
  15          *                                                                           *
  16          ****************************************************************************/
  17          #pragma large
  18          #define __SRC
  19          
  20          #include <main.h>
  21          #undef  __SRC
  22          
  23          
  24          #include <string.h>
  25          #include <intrins.h>
  26          
  27          
  28          #include <stdio.h>
  29          #include <m500a.h>
  30          #include <w77e58.h>
  31          #include <rdio.h>
  32          
  33          #define MIS_CHK_OK              (0)
  34          #define MIS_CHK_FAILED          (-1)
  35          #define MIS_CHK_COMPERR         (-2)
  36          
  37          // Function: mifs_request
  38          #define IDLE                    0x00
  39          #define ALL                     0x01
  40          
  41          
  42          // PC Debug Data: 02 30 31 32 03 33     checksum =33 (30^31^32)
  43          // Release Number of the Firmware
  44          uchar code SW_Rel[] = "\n\r MFRC500 V1.0 8.03.2003 \n\r";
  45          uchar code ms[4][2] = {{0x0,0x0},{0x0,0x0},{0x0,0x0},{0x0,0x0}};
  46          
  47          // Serial Number of the MFRC500
  48          //uchar Snr_RC500[4];
  49          uchar xdata Snr_RC500[4];
  50          //static uint Crc;
  51          
  52          // Local Prototypes
  53          void init(void);
  54          void cmd_execution(void);
  55          
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 2   

  56          // Interrupt Service Routines
  57          void isr_timer0(void);
  58          void isr_UART(void);
  59          
  60          //uchar card_snr[4];
  61          uchar  xdata card_snr[4];
  62          char   xdata ErrNum;
  63          
  64          unsigned char code CmdData_1[]={0x7f,0x40,0x05,0x0,0x0,0x0,0x0};
  65          
  66          unsigned char code CmdData_2[]={0x7f,0x42,0x08,0x0,0x0,0x0,0x0,0x0};
  67          
  68          uchar xdata SectorNum, BlockNum,CommandNum,Key[6],CardData[16],KeyData[6];
  69          
  70          uchar xdata CardSnrNum[6];
  71          
  72          uchar xdata SnrErr;
  73          
  74          void main (void)
  75          { 
  76   1        init();
  77   1      
  78   1        test();       
  79   1      
  80   1        M500PcdConfig();      // Initialise the RC500
  81   1                                  // must be call in the initialization
  82   1      
  83   1      //  RC500 E2PROM  0x00--0x0f Product Information Field
  84   1      //                0x08--0x0b  Product Serial Number
  85   1       
  86   1        PcdReadE2(8,4,Snr_RC500); // Read out the MFRC500 serial number and store it
  87   1          
  88   1        RingOn();
  89   1      
  90   1        while(1)
  91   1        {
  92   2          init();
  93   2          M500PcdConfig();
  94   2      
  95   2      // 检测是否有MIFARE卡在读头感应区,有卡将卡号发送到PC机
  96   2         /*   
  97   2          while(!AccOk)
  98   2          {
  99   2            memcpy(SerBuffer,CmdData_1,7);
 100   2            cmd_execution();
 101   2      
 102   2                AccOk = FALSE ;
 103   2          
 104   2            memcpy(SerBuffer,CmdData_2,8);
 105   2      
 106   2           // 命令码: 0x42:  执行 Anticoll 返回序列号
 107   2            cmd_execution();
 108   2      
 109   2           }
 110   2          
 111   2          AccOk = FALSE ;   
 112   2           
 113   2          TransHexAsi(&SerBuffer[3],SendBuffer,4);//4字节卡序列号
 114   2      
 115   2          SendDataToPc(SendBuffer,8);//发送8字节ASCII码到PC      
 116   2          */
 117   2          AccOk = FALSE ;
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 3   

 118   2          //等待PC 发送命令
 119   2         // while(!FrameOk); 
 120   2          //RingOn();   
 121   2          
 122   2          TransData(PcData,SerBuffer,DataLen);//SerBuffer: PC 与MCU交互数据缓冲区
 123   2      
 124   2          /*
 125   2           cmd_execution() 命令执行程序
 126   2           命令码:               命令功能:
 127   2           0x40:                  // PICC_REQALL
 128   2           0x41:                  // Request
 129   2           0x42:                  // Anticoll
 130   2           0x43:                  // Select
 131   2           0x44:                  // Authentication
 132   2           0x45:                  // Halt
 133   2               0x46:                  // Read
 134   2           0x47:                  // Write
 135   2               0x48:                  // Increment
 136   2           0x49:                                      // Decrement
 137   2           0x4A:                                      // Restore
 138   2               0x4B:                                  // Transfer
 139   2               0x4C:                                  // Load Key
 140   2           0x4D:                                      // comm check char
 141   2           0x4E:                                      // Reset
 142   2           0x4F:                      // Get Info
 143   2           0x50:                                      // Set Control Bit
 144   2           0x51:                                      // Clr Control Bit
 145   2           0x52:                      // Config
 146   2           0x53:                                      // Check Write
 147   2           0x54:                                      // Set Port
 148   2           0x55:                                      // Get Port
 149   2           0x56:                      // Authentication2
 150   2           0x57:                  // Decrement+Transfer
 151   2          */
 152   2          CommandNum =  SerBuffer[0]; //命令码
 153   2          SectorNum =  SerBuffer[1];  //mifare1卡:扇区号
 154   2          BlockNum =  SerBuffer[2];   //mifare1卡:块号 
 155   2          memcpy(KeyData,&SerBuffer[3],6);//mifare1卡:块密码6字节
 156   2          memcpy(CardData,&SerBuffer[3],16);//mifare1卡:待写的16字节数据
 157   2      
 158   2          FrameOk = 0;
 159   2          if(CommandNum == 0x4c)
 160   2          {      
 161   3           
 162   3             SerBuffer[1] = 0x4c;
 163   3             SerBuffer[MODE] = PICC_AUTHENT1A;  //MODE = 3
 164   3             SerBuffer[SECNR] = SectorNum;      //SECNR = 4
 165   3             memcpy(&SerBuffer[13],KeyData,6);
 166   3             cmd_execution();
 167   3             if(!ErrNum)
 168   3             {
 169   4                   SerBuffer[3] = 0x0;
 170   4                   TransHexAsi(&SerBuffer[3],SendBuffer,1);
 171   4                   SendDataToPc(SendBuffer,2);
 172   4                   RingOn();
 173   4             }
 174   3             
 175   3          }  
 176   2      
 177   2          else 
 178   2          {     
 179   3            memcpy(SerBuffer,CmdData_1,7);  //命令码:0x40  执行PICC_REQALL 返回卡型2字节 
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 4   

 180   3      
 181   3            cmd_execution();
 182   3      
 183   3           if(!ErrNum)               
 184   3           {
 185   4            
 186   4              memcpy(SerBuffer,CmdData_2,8);
 187   4      
 188   4              cmd_execution();//命令码:0x42: 执行 Anticoll 返回序列号
 189   4      
 190   4              AccOk = FALSE ;
 191   4      
 192   4              memcpy(card_snr,&SerBuffer[SERNR],4);
 193   4      //--------------------------------------------------------------------------
 194   4      // | 02 | 10 ASCII Data |Characters Checksum | CR | LF | 03 |
 195   4      //--------------------------------------------------------------------------        
 196   4              SnrErr = CheckSnrNum();
 197   4              if(SnrErr == 0)
 198   4              {
 199   5                SendSnrNum();   //发送序列号:02+10字节(0xff+0x + + + + )+checksum(2字节)+0d + 0a + 03      
 200   5                FlashLED();
 201   5              }
 202   4      /*       
 203   4              if(!ErrNum)
 204   4              {
 205   4                 SerBuffer[1] = 0x43;
 206   4      
 207   4                 cmd_execution();// 命令码: 0x43:  选择卡片 返回卡片的 SIZE 字节 0x88h 
 208   4      
 209   4                 AccOk = FALSE ;
 210   4      
 211   4                 SerBuffer[1] = 0x44;
 212   4                 SerBuffer[2] = BlockNum;
 213   4      
 214   4                 SerBuffer[3] = 0 ;
 215   4              
 216   4                 SerBuffer[4] = SectorNum; //卡扇区号(0-15):= 2(含块8,9,10)
 217   4      
 218   4                 cmd_execution();//命令码:0x44: 密码认证操作
 219   4      
 220   4                 if(!ErrNum)
 221   4                 {
 222   4                     if(AuthOk == 0)
 223   4                     {
 224   4                         switch (CommandNum)
 225   4                         {
 226   4                           case 0x46:
 227   4                             SerBuffer[1] = 0x46;          //读卡命令
 228   4                             SerBuffer[3] = BlockNum ;     //卡块号(0-63): =8(8,9,10)
 229   4                             cmd_execution();
 230   4                             TransHexAsi(&SerBuffer[3],SendBuffer,16);
 231   4                             SendDataToPc(SendBuffer,32);
 232   4                             break;
 233   4      
 234   4                           case 0x47:
 235   4                             SerBuffer[1] = 0x47;   //写卡命令
 236   4                             SerBuffer[3] = BlockNum ;      //卡块号
 237   4                      
 238   4                             memcpy(&SerBuffer[4],CardData,16);// 16字节 写卡数据
 239   4      
 240   4                             cmd_execution();
 241   4                             if(!ErrNum)
C51 COMPILER V6.23a  MAIN                                                                  08/03/2004 08:47:24 PAGE 5   

 242   4                             {
 243   4                               SerBuffer[3] = 0x0;
 244   4                               TransHexAsi(&SerBuffer[3],SendBuffer,1);
 245   4                               SendDataToPc(SendBuffer,2);
 246   4                               RingOn();
 247   4                             }
 248   4                              break;   
 249   4      
 250   4                           default:
 251   4                              break;
 252   4      
 253   4                         }
 254   4      
 255   4                     }
 256   4      
 257   4                 }
 258   4      
 259   4              }
 260   4            
 261   4      */      
 262   4            
 263   4            }  
 264   3      
 265   3          }
 266   2         
 267   2       //   delay_10ms(50);
 268   2          
 269   2      
 270   2          if(ErrNum)
 271   2          {
 272   3            delay_10ms(5);
 273   3           /*
 274   3            SerBuffer[3] = ErrNum   ;
 275   3            TransHexAsi(&SerBuffer[3],SendBuffer,1);
 276   3            SendDataToPc(SendBuffer,2);
 277   3           */
 278   3          }  
 279   2      
 280   2        }
 281   1      
 282   1      }
 283          

⌨️ 快捷键说明

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