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

📄 zlg500.lst

📁 ZLG500A读卡模块使用指南、函数库及示范程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 1   


C51 COMPILER V7.50, COMPILATION OF MODULE ZLG500
OBJECT MODULE PLACED IN zlg500.OBJ
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE zlg500.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "main.h"
   2          #include <string.h>
   3          #include "mface_3.h"
   4          
   5          #define __SRC
   6          #include "zlg500.h"
   7          #undef  __SRC
   8          
   9          bit bdata newdata=0;
  10                  
  11          void spi_int(void) interrupt 0 using 1
  12          {
  13   1              spi_rcv(spi_buffer);
  14   1              newdata=1;
  15   1      }
  16          
  17          uchar zlg500cmd(uchar length)
  18          {       uchar spi_wdg=10;
  19   1              uchar i,BCC_sum;
  20   1              
  21   1              spi_buffer[length]=spi_buffer[0];
  22   1              for(i=1;i<length;i++)
  23   1              {
  24   2                      spi_buffer[length]^=spi_buffer[i];
  25   2              }
  26   1              spi_buffer[length]=~spi_buffer[length];
  27   1              
  28   1              TH0=0x2c;          //Fosc=11059200,50ms timer interrupt
  29   1              TL0=0xb0;
  30   1              
  31   1              if(spi_send(spi_buffer,length+1)!=SPI_OK)
  32   1                      return SPI_ERR;
  33   1              
  34   1              ET0=0;
  35   1              TF0=0;
  36   1              TR0=1;
  37   1              SPI_REN();
  38   1              while(newdata==0&&spi_wdg!=0)
  39   1              {
  40   2                      if(TF0==1)
  41   2                      {
  42   3                              TH0=0x2c; 
  43   3                  TL0=0xb0;
  44   3                              TF0=0;
  45   3                              spi_wdg--;
  46   3                      }
  47   2              }
  48   1              TR0=0;
  49   1              SPI_RDIS();
  50   1              
  51   1              if(newdata==0)  return SPI_ERR;
  52   1              newdata=0;
  53   1              
  54   1              
  55   1              BCC_sum=spi_buffer[0];
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 2   

  56   1              for(i=1;i<(spi_buffer[LENGTH]+3);i++)
  57   1              {
  58   2                      BCC_sum^=spi_buffer[i];
  59   2              }
  60   1              if(BCC_sum==~spi_buffer[spi_buffer[LENGTH]+3])
  61   1                      return SPI_OK;
  62   1              else    return MI_CRCERR;
  63   1      }
  64          
  65          #if mifs_request_en
  66          uchar mifs_request(uchar _Mode,uchar idata *_TagType)
  67          {       
  68   1              spi_buffer[SEQNR]=0;
  69   1              spi_buffer[COMMAND]=0x41;
  70   1              spi_buffer[LENGTH]=0x01;
  71   1              spi_buffer[MODE]=_Mode;
  72   1              
  73   1              if(zlg500cmd(4)!=SPI_OK)
  74   1                      return SPI_ERR;
  75   1                      
  76   1              if(spi_buffer[STATUS]==MI_OK)
  77   1              {
  78   2                      _TagType[0]=spi_buffer[TAGTYPE];
  79   2                      _TagType[1]=spi_buffer[TAGTYPE+1];
  80   2              }
  81   1              return spi_buffer[STATUS];
  82   1      }
  83          #endif
  84          
  85          #if mifs_anticoll_en
              uchar mifs_anticoll(uchar _Bcnt,uchar idata *_SNR)
              {
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x42;
                      spi_buffer[LENGTH]=0x01;
                      spi_buffer[MODE]=_Bcnt;
                      
                      if(zlg500cmd(4)!=SPI_OK)
                              return SPI_ERR;
                              
                      if(spi_buffer[STATUS]==MI_OK)
                      {
                              memcpy(_SNR,&spi_buffer[SERNR],4);
                      }
                      return spi_buffer[STATUS];
              }
              #endif
 103          
 104          #if mifs_anticoll2_en
              uchar mifs_anticoll2(uchar _Encoll,uchar _Bcnt,uchar idata *_SNR)
              {
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x71;
                      spi_buffer[LENGTH]=0x02;
                      spi_buffer[DATA]=_Encoll;
                      spi_buffer[DATA+1]=_Bcnt;
                      
                      if(zlg500cmd(5)!=SPI_OK)
                              return SPI_ERR;
                              
                      if(spi_buffer[STATUS]==MI_OK)
                      {
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 3   

                              memcpy(_SNR,&spi_buffer[DATA],4);
                      }
                      return spi_buffer[STATUS];
              }
              #endif
 123          
 124          #if mifs_select_en
              uchar mifs_select(uchar idata *_SNR,uchar idata *_Size)
              {
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x43;
                      spi_buffer[LENGTH]=0x04;
                      memcpy(&spi_buffer[SERNR],_SNR,4);
                              
                      if(zlg500cmd(7)!=SPI_OK)
                              return SPI_ERR;
                              
                      if(spi_buffer[STATUS]==MI_OK)
                      {
                              *_Size=spi_buffer[SIZE];
                      }
                      return spi_buffer[STATUS];      
              }
              #endif
 142          
 143          #if mifs_authentication_en
 144          uchar mifs_authentication(uchar _Mode,uchar _SecNr)
 145          {
 146   1              spi_buffer[SEQNR]=0;
 147   1              spi_buffer[COMMAND]=0x44;
 148   1              spi_buffer[LENGTH]=0x02;
 149   1              spi_buffer[MODE]=_Mode;
 150   1              spi_buffer[SECNR]=_SecNr;
 151   1              
 152   1              if(zlg500cmd(5)!=SPI_OK)
 153   1                      return SPI_ERR;
 154   1              
 155   1              return spi_buffer[STATUS];      
 156   1      }
 157          #endif
 158          
 159          #if mifs_authentication2_en
 160          uchar mifs_authentication2(uchar _Mode,uchar _SecNr,uchar _KeyNr)
 161          {
 162   1              spi_buffer[SEQNR]=0;
 163   1              spi_buffer[COMMAND]=0x72;
 164   1              spi_buffer[LENGTH]=0x03;
 165   1              spi_buffer[MODE]=_Mode;
 166   1              if(_SecNr<=32)
 167   1                      spi_buffer[SECNR]=_SecNr;
 168   1              else
 169   1                      spi_buffer[SECNR]=32+((_SecNr-32)<<2);  //为了支持S70卡
 170   1              spi_buffer[DATA+2]=_KeyNr;
 171   1              
 172   1              if(zlg500cmd(6)!=SPI_OK)
 173   1                      return SPI_ERR;
 174   1              
 175   1              return spi_buffer[STATUS];      
 176   1      }
 177          #endif
 178          
 179          #if mifs_authKey_en
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 4   

 180          uchar mifs_authKey(uchar _Mode,uchar _SecNr,uchar *_Key)
 181          {
 182   1              spi_buffer[SEQNR]=0;
 183   1              spi_buffer[COMMAND]=0x73;
 184   1              spi_buffer[LENGTH]=0x08;
 185   1              spi_buffer[DATA]=_Mode;
 186   1              if(_SecNr<=32)
 187   1                      spi_buffer[SECNR]=_SecNr;
 188   1              else
 189   1                      spi_buffer[SECNR]=32+((_SecNr-32)<<2);  //为了支持S70卡
 190   1              memcpy(&spi_buffer[DATA+2],_Key,6);
 191   1                      
 192   1              if(zlg500cmd(11)!=SPI_OK)
 193   1                      return SPI_ERR;
 194   1              
 195   1              return spi_buffer[STATUS];      
 196   1      }
 197          #endif
 198          
 199          #if mifs_halt_en
 200          uchar mifs_halt(void)
 201          {
 202   1              spi_buffer[SEQNR]=0;
 203   1              spi_buffer[COMMAND]=0x45;
 204   1              spi_buffer[LENGTH]=0x00;
 205   1              
 206   1              if(zlg500cmd(3)!=SPI_OK)
 207   1                      return SPI_ERR;
 208   1              
 209   1              return spi_buffer[STATUS];      
 210   1      }
 211          #endif
 212          
 213          #if mifs_read_en
 214          uchar mifs_read(uchar _Adr,uchar idata *_Data)
 215          {
 216   1              spi_buffer[SEQNR]=0;
 217   1              spi_buffer[COMMAND]=0x46;
 218   1              spi_buffer[LENGTH]=0x01;
 219   1              spi_buffer[ADR]=_Adr;
 220   1                      
 221   1              if(zlg500cmd(4)!=SPI_OK)
 222   1                      return SPI_ERR;
 223   1                      
 224   1              if(spi_buffer[STATUS]==MI_OK)
 225   1              {
 226   2                      memcpy(_Data,&spi_buffer[DATABYTES-1],16);
 227   2              }
 228   1              return spi_buffer[STATUS];              
 229   1      }
 230          #endif
 231          
 232          #if mifs_write_en
 233          uchar mifs_write(uchar _Adr,uchar idata *_Data)
 234          {
 235   1              spi_buffer[SEQNR]=0;
 236   1              spi_buffer[COMMAND]=0x47;
 237   1              spi_buffer[LENGTH]=17;
 238   1              spi_buffer[ADR]=_Adr;
 239   1              memcpy(&spi_buffer[DATABYTES],_Data,16);
 240   1                      
 241   1              if(zlg500cmd(20)!=SPI_OK)
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 5   

 242   1                      return SPI_ERR;
 243   1              
 244   1              return spi_buffer[STATUS];              
 245   1      }
 246          #endif
 247          
 248          #if mifs_increment_en
              uchar mifs_increment(uchar _Adr,long idata *_Value)
              {       uchar *temp=(uchar *)_Value;
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x48;
                      spi_buffer[LENGTH]=5;
                      spi_buffer[ADR]=_Adr;
                      spi_buffer[VALUE]=*(temp+3);
                      spi_buffer[VALUE+1]=*(temp+2);
                      spi_buffer[VALUE+2]=*(temp+1);
                      spi_buffer[VALUE+3]=*temp;
                                      
                      if(zlg500cmd(8)!=SPI_OK)
                              return SPI_ERR;
                      
                      return spi_buffer[STATUS];
              }
              #endif
 266          
 267          #if mifs_decrement_en
              uchar mifs_decrement(uchar _Adr,long idata *_Value)
              {
                      uchar *temp=(uchar *)_Value;
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x49;
                      spi_buffer[LENGTH]=5;
                      spi_buffer[ADR]=_Adr;
                      spi_buffer[VALUE]=*(temp+3);
                      spi_buffer[VALUE+1]=*(temp+2);
                      spi_buffer[VALUE+2]=*(temp+1);
                      spi_buffer[VALUE+3]=*temp;
                                      
                      if(zlg500cmd(8)!=SPI_OK)
                              return SPI_ERR;
                      
                      return spi_buffer[STATUS];
              }
              #endif
 286          
 287          #if mifs_restore_en
              uchar mifs_restore(uchar _Adr)
              {
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x4A;
                      spi_buffer[LENGTH]=1;
                      spi_buffer[ADR]=_Adr;
                      
                      if(zlg500cmd(4)!=SPI_OK)
                              return SPI_ERR;
                      
                      return spi_buffer[STATUS];      
              }
              #endif
 301          
 302          #if mifs_transfer_en
              uchar mifs_transfer(uchar _Adr)
C51 COMPILER V7.50   ZLG500                                                                04/23/2009 14:41:45 PAGE 6   

              {
                      spi_buffer[SEQNR]=0;
                      spi_buffer[COMMAND]=0x4B;
                      spi_buffer[LENGTH]=1;
                      spi_buffer[ADR]=_Adr;
                      
                      if(zlg500cmd(4)!=SPI_OK)
                              return SPI_ERR;
                      
                      return spi_buffer[STATUS];
              }
              #endif
 316          

⌨️ 快捷键说明

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