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

📄 zlg500b.lst

📁 ZLG500B读卡模块的程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 1   


C51 COMPILER V7.02b, COMPILATION OF MODULE ZLG500B
OBJECT MODULE PLACED IN zlg500B.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE zlg500B.c BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          #include "main.h"
   2          
   3          #define __SRC
   4          #include "zlg500B.h"
   5          #undef  __SRC
   6          
   7          
   8          
   9          void Serial_int(void) interrupt 4 using 1 
  10          {
  11   1              uchar stx,index,BCC_sum=0,rcv_len=5;
  12   1              
  13   1              ES=0;
  14   1              RI=0;
  15   1              stx=SBUF;
  16   1      
  17   1              delay_50us(1);
  18   1      
  19   1              CON_485=1;
  20   1              REN=0;
  21   1              SBUF=ACK;
  22   1              while(TI==0);
  23   1              TI=0;
  24   1              CON_485=0;
  25   1              REN=1;
  26   1      
  27   1              for(index=0;index<rcv_len;index++)
  28   1              {
  29   2                      START_T2(RCAP2_10ms);
  30   2                      while(RI==0&&TF2==0);   
  31   2                      if(RI==1)
  32   2                      {       RI=0;
  33   3                              ser_buffer[index]=SBUF;
  34   3                              if(index==LENGTH)       rcv_len+=ser_buffer[index];
  35   3                              if(index<rcv_len-2)     BCC_sum^=ser_buffer[index];
  36   3                      }
  37   2                      else    break;
  38   2              }
  39   1              STOP_T2();
  40   1              ES=1;
  41   1              
  42   1              if(stx!=STX)    return;
  43   1              if(index==rcv_len)
  44   1              {
  45   2                      if(BCC_sum!=~ser_buffer[rcv_len-2])     return;
  46   2                      if(ser_buffer[rcv_len-1]!=ETX)  return;
  47   2              }
  48   1              else    return;
  49   1      
  50   1              newdata=1;
  51   1      }       
  52          
  53          
  54          uchar senddata()
  55          {
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 2   

  56   1              uchar send_cnt=3;
  57   1              uchar send_len;
  58   1              uchar temp;
  59   1      
  60   1              ES=0;
  61   1              do
  62   1              {       CON_485=1;
  63   2                      REN=0;
  64   2                      SBUF=STX;
  65   2                      while(TI==0);
  66   2                      TI=0;
  67   2                      CON_485=0;
  68   2      
  69   2                      REN=1;
  70   2                      START_T2(RCAP2_10ms);
  71   2                      while(RI==0&&TF2==0);
  72   2                      STOP_T2();
  73   2      
  74   2                      if(RI==1)
  75   2                      {       RI=0;
  76   3                              temp=SBUF;
  77   3                              delay_50us(1);
  78   3                              if(temp==ACK)   break;
  79   3                      }
  80   2              }while(--send_cnt);
  81   1              if(send_cnt==0) return COMM_ERR;
  82   1                      
  83   1              
  84   1              send_len=ser_buffer[LENGTH]+5;
  85   1              ser_buffer[send_len-2]=0;
  86   1              ser_buffer[send_len-1]=ETX;
  87   1              
  88   1              REN=0;
  89   1              CON_485=1;
  90   1              for(send_cnt=0;send_cnt<send_len;send_cnt++)
  91   1              {
  92   2                      SBUF=ser_buffer[send_cnt];
  93   2                      if(send_cnt<(send_len-2))
  94   2                              ser_buffer[send_len-2]^=ser_buffer[send_cnt];
  95   2                      if(send_cnt==send_len-3)
  96   2                              ser_buffer[send_len-2]=~ser_buffer[send_len-2];
  97   2                      while(TI==0);
  98   2                      TI=0;
  99   2              }
 100   1              CON_485=0;
 101   1              REN=1;
 102   1              ES=1;
 103   1              
 104   1              return  COMM_OK;
 105   1      }
 106          
 107          uchar ser_comm(void)
 108          {
 109   1              uchar ser_wdg=120;
 110   1              if(senddata()!=COMM_OK) return COMM_ERR;
 111   1      
 112   1              START_T2(RCAP2_2ms);
 113   1              while(newdata==0&&ser_wdg!=0)
 114   1              {
 115   2                      if(TF2)
 116   2                      {
 117   3                              START_T2(RCAP2_2ms);
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 3   

 118   3                              ser_wdg--;
 119   3                      }
 120   2              }
 121   1              if(newdata)     
 122   1              {       
 123   2                      newdata=0;
 124   2                      return COMM_OK;
 125   2              }
 126   1              else
 127   1                      return COMM_ERR;        
 128   1      }
 129          
 130          #if mifs_request_en
 131          uchar mifs_request(uchar _Mode,uchar idata *_TagType)
 132          {       
 133   1              ser_buffer[SEQNR]=0;
 134   1              ser_buffer[COMMAND]=0x41;
 135   1              ser_buffer[LENGTH]=0x01;
 136   1              ser_buffer[DATA]=_Mode;
 137   1              
 138   1              if(ser_comm()!=COMM_OK)
 139   1                      return COMM_ERR;
 140   1                      
 141   1              if(ser_buffer[STATUS]==MI_OK)
 142   1              {
 143   2                      _TagType[0]=ser_buffer[DATA];
 144   2                      _TagType[1]=ser_buffer[DATA+1];
 145   2              }
 146   1              return ser_buffer[STATUS];
 147   1      }
 148          #endif
 149          
 150          #if mifs_anticoll_en
              uchar mifs_anticoll(uchar _Bcnt,uchar idata *_SNR)
              {
                      ser_buffer[SEQNR]=0;
                      ser_buffer[COMMAND]=0x42;
                      ser_buffer[LENGTH]=0x01;
                      ser_buffer[DATA]=_Bcnt;
                      
                      if(ser_comm()!=COMM_OK)
                              return COMM_ERR;
                              
                      if(ser_buffer[STATUS]==MI_OK)
                      {
                              memcpy(_SNR,&ser_buffer[DATA],4);
                      }
                      return ser_buffer[STATUS];
              }
              #endif
 168          
 169          #if mifs_anticoll2_en
              uchar mifs_anticoll2(uchar _Encoll,uchar _Bcnt,uchar idata *_SNR)
              {
                      ser_buffer[SEQNR]=0;
                      ser_buffer[COMMAND]=0x71;
                      ser_buffer[LENGTH]=0x02;
                      ser_buffer[DATA]=_Encoll;
                      ser_buffer[DATA+1]=_Bcnt;
                      
                      if(ser_comm()!=COMM_OK)
                              return COMM_ERR;
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 4   

                              
                      if(ser_buffer[STATUS]==MI_OK)
                      {
                              memcpy(_SNR,&ser_buffer[DATA],4);
                      }
                      return ser_buffer[STATUS];
              }
              #endif
 188          
 189          #if mifs_select_en
              uchar mifs_select(uchar idata *_SNR,uchar idata *_Size)
              {
                      ser_buffer[SEQNR]=0;
                      ser_buffer[COMMAND]=0x43;
                      ser_buffer[LENGTH]=0x04;
                      memcpy(&ser_buffer[DATA],_SNR,4);
                              
                      if(ser_comm()!=COMM_OK)
                              return COMM_ERR;
                              
                      if(ser_buffer[STATUS]==MI_OK)
                      {
                              *_Size=ser_buffer[DATA];
                      }
                      return ser_buffer[STATUS];      
              }
              #endif
 207          
 208          #if mifs_authentication_en
 209          uchar mifs_authentication(uchar _Mode,uchar _SecNr)
 210          {
 211   1              ser_buffer[SEQNR]=0;
 212   1              ser_buffer[COMMAND]=0x44;
 213   1              ser_buffer[LENGTH]=0x02;
 214   1              ser_buffer[DATA]=_Mode;
 215   1              ser_buffer[DATA+1]=_SecNr;
 216   1              
 217   1              if(ser_comm()!=COMM_OK)
 218   1                      return COMM_ERR;
 219   1              
 220   1              return ser_buffer[STATUS];      
 221   1      }
 222          #endif
 223          
 224          #if mifs_authentication2_en
 225          uchar mifs_authentication2(uchar _Mode,uchar _SecNr,uchar _KeyNr)
 226          {
 227   1              ser_buffer[SEQNR]=0;
 228   1              ser_buffer[COMMAND]=0x72;
 229   1              ser_buffer[LENGTH]=0x03;
 230   1              ser_buffer[DATA]=_Mode;
 231   1              if(_SecNr<=32)
 232   1                      ser_buffer[DATA+1]=_SecNr;
 233   1              else
 234   1                      ser_buffer[DATA+1]=32+((_SecNr-32)<<2); //为了支持S70卡
 235   1              ser_buffer[DATA+2]=_KeyNr;
 236   1              
 237   1              if(ser_comm()!=COMM_OK)
 238   1                      return COMM_ERR;
 239   1              
 240   1              return ser_buffer[STATUS];      
 241   1      }
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 5   

 242          #endif
 243          
 244          #if mifs_authKey_en
 245          uchar mifs_authKey(uchar _Mode,uchar _SecNr,uchar *_Key)
 246          {
 247   1              ser_buffer[SEQNR]=0;
 248   1              ser_buffer[COMMAND]=0x73;
 249   1              ser_buffer[LENGTH]=0x08;
 250   1              ser_buffer[DATA]=_Mode;
 251   1              if(_SecNr<=32)
 252   1                      ser_buffer[DATA+1]=_SecNr;
 253   1              else
 254   1                      ser_buffer[DATA+1]=32+((_SecNr-32)<<2); //为了支持S70卡
 255   1              memcpy(&ser_buffer[DATA+2],_Key,6);
 256   1              
 257   1              
 258   1              if(ser_comm()!=COMM_OK)
 259   1                      return COMM_ERR;
 260   1              
 261   1              return ser_buffer[STATUS];      
 262   1      }
 263          #endif
 264          
 265          #if mifs_halt_en
 266          uchar mifs_halt(void)
 267          {
 268   1              ser_buffer[SEQNR]=0;
 269   1              ser_buffer[COMMAND]=0x45;
 270   1              ser_buffer[LENGTH]=0x00;
 271   1              
 272   1              if(ser_comm()!=COMM_OK)
 273   1                      return COMM_ERR;
 274   1              
 275   1              return ser_buffer[STATUS];      
 276   1      }
 277          #endif
 278          
 279          #if mifs_read_en
 280          uchar mifs_read(uchar _Adr,uchar idata *_Data)
 281          {
 282   1              ser_buffer[SEQNR]=0;
 283   1              ser_buffer[COMMAND]=0x46;
 284   1              ser_buffer[LENGTH]=0x01;
 285   1              ser_buffer[DATA]=_Adr;
 286   1                      
 287   1              if(ser_comm()!=COMM_OK)
 288   1                      return COMM_ERR;
 289   1                      
 290   1              if(ser_buffer[STATUS]==MI_OK)
 291   1              {
 292   2                      memcpy(_Data,&ser_buffer[DATA],16);
 293   2              }
 294   1              return ser_buffer[STATUS];              
 295   1      }
 296          #endif
 297          
 298          #if mifs_write_en
 299          uchar mifs_write(uchar _Adr,uchar idata *_Data)
 300          {
 301   1              ser_buffer[SEQNR]=0;
 302   1              ser_buffer[COMMAND]=0x47;
 303   1              ser_buffer[LENGTH]=17;
C51 COMPILER V7.02b   ZLG500B                                                              03/02/2006 18:25:04 PAGE 6   

 304   1              ser_buffer[DATA]=_Adr;
 305   1              memcpy(&ser_buffer[DATA+1],_Data,16);
 306   1                      
 307   1              if(ser_comm()!=COMM_OK)
 308   1                      return COMM_ERR;
 309   1              
 310   1              return ser_buffer[STATUS];              
 311   1      }
 312          #endif
 313          
 314          #if mifs_increment_en
              uchar mifs_increment(uchar _Adr,long idata *_Value)
              {       uchar *temp=(uchar *)_Value;
                      ser_buffer[SEQNR]=0;
                      ser_buffer[COMMAND]=0x48;
                      ser_buffer[LENGTH]=5;
                      ser_buffer[DATA]=_Adr;
                      ser_buffer[DATA+1]=*(temp+3);
                      ser_buffer[DATA+2]=*(temp+2);
                      ser_buffer[DATA+3]=*(temp+1);
                      ser_buffer[DATA+4]=*temp;
                                      
                      if(ser_comm()!=COMM_OK)
                              return COMM_ERR;
                      
                      return ser_buffer[STATUS];
              }
              #endif
 332          
 333          #if mifs_decrement_en
              uchar mifs_decrement(uchar _Adr,long idata *_Value)
              {
                      uchar *temp=(uchar *)_Value;
                      ser_buffer[SEQNR]=0;
                      ser_buffer[COMMAND]=0x49;
                      ser_buffer[LENGTH]=5;
                      ser_buffer[DATA]=_Adr;
                      ser_buffer[DATA+1]=*(temp+3);
                      ser_buffer[DATA+2]=*(temp+2);
                      ser_buffer[DATA+3]=*(temp+1);
                      ser_buffer[DATA+4]=*temp;
                                      
                      if(ser_comm()!=COMM_OK)
                              return COMM_ERR;
                      
                      return ser_buffer[STATUS];
              }
              #endif
 352          
 353          #if mifs_restore_en

⌨️ 快捷键说明

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