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

📄 r6c.lst

📁 采用C52+R6C完成的ISO15693标准的刷卡器程序
💻 LST
📖 第 1 页 / 共 2 页
字号:
C51 COMPILER V8.08   R6C                                                                   01/18/2009 20:00:52 PAGE 1   


C51 COMPILER V8.08, COMPILATION OF MODULE R6C
OBJECT MODULE PLACED IN r6c.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE r6c.c BROWSE DEBUG OBJECTEXTEND

line level    source

   1          #include "typedef.h"
   2          
   3          
   4          
   5          ////////////////////////////////////////////////////
   6          void _sendBit(bit temp)
   7          {
   8   1              DIN = 1;
   9   1              SCLOCK = 0; _nop_();    
  10   1              DIN = temp; _nop_();  
  11   1              SCLOCK = 1; _nop_(); 
  12   1              SCLOCK = 0;
  13   1      }
  14          /************************************************************************/
  15          /* clockmaster transfer from uctrl to ASIC*/
  16          /************************************************************************/
  17          void _trans1(void)
  18          {
  19   1              SCLOCK = 0;  
  20   1              DIN = 0;  _nop_();
  21   1              DIN = 1;  _nop_();
  22   1              DIN = 0;  _nop_();
  23   1              DIN = 1;  _nop_();
  24   1              SCLOCK = 1;_nop_();
  25   1      }
  26          /*****************************************************************/
  27          /* clockmaster transfer from ASIC to uctrl************************/
  28          /*****************************************************************/
  29          
  30          void _trans2(void)
  31          {
  32   1              SCLOCK = 0;  
  33   1              DIN = 1;   _nop_();
  34   1              DIN = 0;  _nop_();
  35   1              DIN = 1;  _nop_();
  36   1              DIN = 0;  _nop_();
  37   1      }
  38          
  39          /*****************************************************************/
  40          /*startbit S1:rising edge on Din while SCLOCK high   *************/
  41          /*****************************************************************/
  42          void _startBit(void)
  43          { 
  44   1              SCLOCK = 0;    _nop_(); 
  45   1              DIN    = 0;    _nop_(); 
  46   1              SCLOCK = 1;    _nop_(); 
  47   1              DIN    = 1;    _nop_(); 
  48   1              SCLOCK = 0;    _nop_(); 
  49   1      }
  50          
  51          /*****************************************************************/
  52          /* stopbit ES1:falling edge on Din while SCLOCK high  ************/
  53          /*****************************************************************/
  54          void _stopBit(void)
  55          { 
C51 COMPILER V8.08   R6C                                                                   01/18/2009 20:00:52 PAGE 2   

  56   1              SCLOCK = 0;  _nop_();
  57   1              DIN    = 1;  _nop_();
  58   1              SCLOCK = 1;  _nop_();
  59   1              DIN    = 0;  _nop_();
  60   1              SCLOCK = 0;  _nop_();
  61   1      }
  62          /*****************************************************************/
  63          /* find S2:  a SOF sent by the TAG *******************************/
  64          /*****************************************************************/
  65          bit TIMERINT;
  66          
  67          uchar _findS2(void)
  68          {
  69   1              uchar S2=0;
  70   1              while ((!SCLOCK)&&(!TIMERINT)); //等到SCLK变高
  71   1              if (SCLOCK)                                             //sclk变到高电平
  72   1              {
  73   2                      while ((SCLOCK)&&(!TIMERINT)&&(!DOUT)); //等到dout输出为高
  74   2                      if (DOUT)       //dout已经为高电平
  75   2                      {
  76   3                              while ((SCLOCK)&&(!TIMERINT)&&(DOUT));//等sclk变为低电平,dout为高
  77   3                              if (!SCLOCK)
  78   3                              {
  79   4                                      S2 = 1; //找到起始信号
  80   4                              }
  81   3                      }
  82   2              }
  83   1              return (S2);
  84   1      }
  85          
  86          /*****************************************************************/
  87          /* readbit:read data from DOUT*************************************/
  88          /*****************************************************************/
  89          uchar _readbit(void)
  90          {
  91   1              uchar i, sample, doutstore;
  92   1              uchar debounce=1;                                       // min clockpulse is 4.7us for 106kBaud
  93   1              while ((!SCLOCK)&&(!TIMERINT));         //wait for rising edge
  94   1         
  95   1              for (i=0; i<debounce;i++); 
  96   1              if (SCLOCK)
  97   1              {
  98   2                      if(M_ERR)
  99   2                      {  
 100   3                              if(M_ERR) { sample = 2; return (sample); }
 101   3                      }
 102   2                      doutstore=DOUT;
 103   2                      if (!DOUT)
 104   2                              sample = 0;
 105   2                      else
 106   2                              sample = 1;                             //store sample: no debouncing!
 107   2                      
 108   2                      while ((SCLOCK)&&(!TIMERINT)&&(doutstore ==DOUT));
 109   2                      
 110   2                      if ((SCLOCK)&&(doutstore != DOUT) )             // ES2
 111   2                      {
 112   3                              sample = 0x03;
 113   3                      }
 114   2                      else if (TIMERINT)                                              // timeout
 115   2                      {
 116   3                              sample = 0x04;
 117   3                      }         
C51 COMPILER V8.08   R6C                                                                   01/18/2009 20:00:52 PAGE 3   

 118   2              }
 119   1              return(sample);  
 120   1      }
 121          
 122          /*****************************************************************/
 123          /***read on DOUT and write on DIN, with uctrl master of clock.****/
 124          /*****************************************************************/
 125          
 126          uchar _rwbit(uchar wbit)
 127          { 
 128   1              uchar i, rbit;
 129   1              if(wbit)
 130   1                      DIN = 1;
 131   1              else
 132   1                      DIN = 0;
 133   1              SCLOCK = 1;
 134   1              DOUT = 1;
 135   1              for (i=0;i<2;i++); //dummy
 136   1              if (!DOUT)
 137   1                      rbit=0;
 138   1              else
 139   1                      rbit=1;
 140   1              SCLOCK = 0;
 141   1              return (rbit);
 142   1      }
 143          /*****************************************************************/
 144          
 145          unsigned char prgCnt = 0;
 146          uchar pwUpScanCnt = 0;
 147          uchar spkerCnt = 0;
 148          uchar timeout;
 149          bit b_spker = 0;
 150          bit b_com_r6c;
 151          
 152          void time(void) interrupt 1 using 2
 153          {
 154   1              
 155   1              TH0=0xdc;                    //10ms的基准定时,11.0592M
 156   1              TL0=0x00;
 157   1      
 158   1              prgCnt ++;      //prg run
 159   1              pwUpScanCnt ++; 
 160   1              if(b_spker)spkerCnt++;
 161   1              if(b_com_r6c) 
 162   1              {
 163   2                      timeout --;
 164   2                      if(timeout==0)
 165   2                      { 
 166   3                              TIMERINT=1;
 167   3                              b_com_r6c=0;
 168   3                      }
 169   2              }
 170   1      
 171   1      }
 172          /**************************************************************/
 173          
 174          BOOL _setTimer(uchar timeout_temp)
 175          {
 176   1              b_com_r6c = 1;
 177   1              timeout = timeout_temp;
 178   1              TIMERINT= 0;
 179   1              TR0 = 1;
C51 COMPILER V8.08   R6C                                                                   01/18/2009 20:00:52 PAGE 4   

 180   1              return(TRUE);
 181   1      }
 182          void _clrTimer(void)
 183          {
 184   1              b_com_r6c = 0;
 185   1              timeout = 0;
 186   1              TIMERINT = 0;
 187   1      }
 188          
 189          
 190          /**************************************************************/
 191          
 192          
 193          uchar idata pcdata[140];  
 194          uchar code tab1[16]={0x00,0x08,0x04,0x0c,0x02,0x0a,0x06,0x0e ,0x01,0x09,0x05,0x0d,0x03,0x0b,0x07,0x0f};
 195          
 196          ////////////////////////////////////////////////////////////////////
 197          
 198          BYTE ReflectBYTE(BYTE byOrg) 
 199          {
 200   1              BYTE j,k;
 201   1              j = byOrg & 0x0f;
 202   1              j = tab1[j];
 203   1              j = j<<4;
 204   1              k = byOrg>>4;
 205   1              k = tab1[k];
 206   1              j = j + k;
 207   1              return(j);
 208   1      }
 209          
 210          #define POLYNOMIAL  0x8408   /*x^16+x^12+x^5+1*/
 211          #define PRESET_VALUE 0xFFFF
 212          #define CHECK_VALUE 0xF0B8
 213          #define CALC_CRC     1
 214          #define CHECK_CRC    0
 215          
 216          WORD crc16Calculate(BYTE idata * pBuf,BYTE byLen)
 217          {
 218   1              unsigned int current_crc_value;
 219   1              BYTE i,j;
 220   1              current_crc_value = PRESET_VALUE;
 221   1              for(i=0;i<byLen;i++)
 222   1              {
 223   2                      current_crc_value = current_crc_value^pBuf[i];
 224   2                      for(j=0;j<8;j++)
 225   2                      {
 226   3                              if(current_crc_value & 0x0001)
 227   3                              {
 228   4                                      current_crc_value = (current_crc_value>>1)^POLYNOMIAL;
 229   4                              }
 230   3                              else
 231   3                              {
 232   4                                      current_crc_value = (current_crc_value>>1);
 233   4                              }
 234   3                      }
 235   2              }
 236   1              current_crc_value = ~current_crc_value;         //?????
 237   1              return(current_crc_value);
 238   1       } 
 239          
 240          #define HIBYTE(w)       ((BYTE)(w>>8))
 241          #define LOBYTE(w)       ((BYTE)(w))
C51 COMPILER V8.08   R6C                                                                   01/18/2009 20:00:52 PAGE 5   

 242          bit chkCRC(BYTE idata * cBuf,BYTE cLen)
 243          {
 244   1         bit flag =1;
 245   1         uchar i;
 246   1         uint j;
 247   1         for(i=0;i<cLen;i++) { cBuf[i] = ReflectBYTE(cBuf[i]); }
 248   1         j = crc16Calculate(cBuf,cLen-2);
 249   1         flag  = (cBuf[cLen-2] == LOBYTE(j) );                //crc LSByte
 250   1         flag &= (cBuf[cLen-1] == HIBYTE(j) );                //crc MSByte
 251   1         return(flag);

⌨️ 快捷键说明

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