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

📄 main.lst

📁 EM4001,EM4100等系列只读ID卡读取程序源码
💻 LST
字号:
C51 COMPILER V7.50   MAIN                                                                  07/20/2005 09:23:27 PAGE 1   


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

line level    source

   1          #include <sst/SST89x5x4.H>
   2          #include <string.h>
   3          #include <stdio.h>
   4          //PCA REGS
   5          
   6          sfr CH=0xF9;  //PCA COUNER/TIMER
   7          sfr CL=0xE9;
   8          
   9          sfr CCON=0xD8;
  10          sfr CMOD=0xD9;
  11          
  12          sfr CCAPM0=0xDA;
  13          sfr CCAPM1=0xDB;
  14          sfr CCAPM2=0xDC;
  15          sfr CCAPM3=0xDD;
  16          sfr CCAPM4=0xDE;
  17          
  18          sfr CCAP0H=0xFA;
  19          sfr CCAP0L=0xEA;
  20          sfr CCAP1H=0xFB;
  21          sfr CCAP1L=0xEB;
  22          sfr CCAP2H=0xFC;
  23          sfr CCAP2L=0xEC;
  24          sfr CCAP3H=0xFD;
  25          sfr CCAP3L=0xED;
  26          sfr CCAP4H=0xFE;
  27          sfr CCAP4L=0xEE;
  28          
  29          sbit CCF0=CCON^0;
  30          sbit CCF4=CCON^4;
  31          sbit CR=CCON^6;
  32          
  33          
  34          // This program is designed to use the PCA module to calculate the width of a
  35          // detected pulse. The pulse must begin with a rising edge and end with a falling
  36          // edge on the CEX0 pin.
  37          // The HEADER FILE “SST89X5X4.h” is an SST proprietary header file that defines SST’s SFRs.
  38          // This file can be found on the SST website, or the BSL Demo Kit.
  39          bit flag = 0; // Rising or falling edge flag.
  40          unsigned int pulse_width = 0x00; // Final pulse width calculation is stored here.
  41          unsigned int capture1 = 0x00; // Rising edge captured here.
  42          unsigned int capture2 = 0x00; // Falling edge captured here.
  43          unsigned char buf_p=0,buf_p2=0;
  44          unsigned char idata dat[129],iddat[10];
  45          
  46          unsigned char code bitcode[]={0x80,0x40,0x20,0x10,0x08,0x04,0x02,0x01};
  47          
  48          /*
  49          void PCA_ISR() interrupt 6 // PCA Interrupt Service routine
  50          {
  51           unsigned int temp;
  52          
  53           CCF4 = 0; // Clear the PCA flag
  54          
  55           if (flag == 0)
C51 COMPILER V7.50   MAIN                                                                  07/20/2005 09:23:27 PAGE 2   

  56           {
  57                  capture1 = CCAP4L | (CCAP4H << 8); // If positive edge, store in
  58          
  59                  CCAPM4 = 0x11; // capture1. Setup module
  60          
  61                  flag = 1; // 0 for capturing falling edge
  62            
  63              temp=(capture1-capture2)/100;
  64          
  65          }
  66          else
  67          {
  68                  capture2 = CCAP4L | (CCAP4H << 8); // Capture falling edge
  69          
  70                  CCAPM4 = 0x21; // Setup module 0 for capturing rising edge.
  71          
  72                  flag = 0; // Reset flag 
  73          
  74                  temp=(capture2-capture1)/100;
  75          
  76           }
  77           
  78             if(temp<2)return;
  79            if(temp>12)return;
  80          
  81            if( temp<6 )                //分解数据,脉宽判断
  82                 dat[buf_p++]=flag;
  83          
  84            else 
  85            {
  86                 dat[buf_p++]=flag;
  87                 dat[buf_p++]=flag;
  88                  
  89          
  90          
  91            }
  92          
  93           if( buf_p< 17)                        //起始位判断
  94           if(dat[buf_p-1] != ( (buf_p-1) & 1))  
  95             buf_p=0;                                      
  96          
  97           if( buf_p >=128 )
  98           {  
  99              buf_p=128;
 100              CCAPM4=0;
 101                  CMOD=0;
 102                  CR = 0; 
 103                  IE = 0x00; 
 104           }        
 105          }
 106          */
 107          void PCA_intr()interrupt 6 using 1
 108          {
 109   1               
 110   1                      CCF4=0;
 111   1                      if(flag==0)
 112   1                      {
 113   2                      capture1 = CCAP4L|(CCAP4H<<8);
 114   2                      CCAPM4=0x11;                                     //设置为下降沿中断
 115   2                      flag=1;
 116   2                      pulse_width=(capture1-capture2)/100;
 117   2                      }
C51 COMPILER V7.50   MAIN                                                                  07/20/2005 09:23:27 PAGE 3   

 118   1              else
 119   1                      {
 120   2                      capture2=CCAP4L|(CCAP4H<<8);
 121   2                      pulse_width=(capture2-capture1)/100;
 122   2                      CCAPM4 = 0x21;                                                                  //设置为上升沿中断
 123   2                      flag=0;
 124   2      
 125   2                      }
 126   1      
 127   1               
 128   1      
 129   1                      if((pulse_width<2)||(pulse_width>12))
 130   1                              return;
 131   1                       
 132   1      
 133   1                      if( pulse_width<6 )                //分解数据,脉宽判断
 134   1                       dat[buf_p++]=flag;                     
 135   1                      else 
 136   1                      {
 137   2                     dat[buf_p++]=flag;
 138   2                     dat[buf_p++]=flag;
 139   2                      }
 140   1       
 141   1                      if( buf_p< 17)                        //起始位判断
 142   1                      {
 143   2                              if( dat[buf_p-1] != ( (buf_p-1) & 1))  //如果不是1,剔除
 144   2                                      buf_p=0;                                      
 145   2                      } 
 146   1                      if( buf_p >=128 )
 147   1                      {  
 148   2                          buf_p=128;
 149   2                          CCAPM4=0;
 150   2                              CMOD=0;
 151   2                              CR = 0; 
 152   2                              IE = 0x00;                                              //停止中断使能
 153   2                      }        
 154   1              
 155   1      
 156   1      }
 157          
 158          
 159           /*
 160          bit check_emid(unsigned char *dat,unsigned char *out,unsigned int len)
 161          {
 162             unsigned int i,j,k;   
 163             unsigned char result=0;
 164          //   unsigned char check;
 165             unsigned char code head[]={1,1,1,1,1,1,1,1,0};
 166          
 167             if( memcmp(head,dat,9) != 0 )return 0;    
 168          
 169             i=8;
 170          
 171             for(j=0;j<10;j++)
 172             {
 173               result=0;
 174          
 175               for(k=0;k<4;k++)
 176               {
 177                result <<=1;
 178                if(dat[i+j*5+k])
 179                         result |=0x01;
C51 COMPILER V7.50   MAIN                                                                  07/20/2005 09:23:27 PAGE 4   

 180                   }
 181           
 182                   if(!(j % 2))out[j/2]=result;
 183                   else
 184               {
 185                 out[j/2]=(out[j/2]<<4)+result;     
 186               }
 187             }
 188          
 189             return 1;
 190          }*/
 191          bit check_emid(unsigned char *dat,unsigned char *out )
 192          {
 193   1         unsigned int i,j,k;   
 194   1         unsigned char result=0;
 195   1          
 196   1         unsigned char code head[]={1,1,1,1,1,1,1,1,0};
 197   1      
 198   1         if( memcmp(head,dat,9) != 0 )
 199   1                      return 0;    
 200   1      
 201   1         i=8;
 202   1      
 203   1         for(j=0;j<10;j++)
 204   1         {
 205   2           result=0;
 206   2      
 207   2           for(k=0;k<4;k++)
 208   2           {
 209   3            result <<=1;
 210   3            if(dat[i+j*5+k])
 211   3                     result |=0x01;
 212   3               }
 213   2       
 214   2               if(!(j % 2))
 215   2                      out[j/2]=result;
 216   2               else
 217   2           {
 218   3             out[j/2]=(out[j/2]<<4)+result;                                           //2组4bit 组成一个字节
 219   3           }
 220   2         }
 221   1      
 222   1         return 1;
 223   1      }
 224          
 225          void pcaint()
 226          {
 227   1      CMOD = 0x01; //Setting up the PCA counter
 228   1       CH = 0x00;
 229   1       CL = 0x00;
 230   1       CCAPM4 = 0x21; // Setup module zero in capture mode
 231   1       flag = 0;
 232   1       IE = 0xC0; // Enable PCA interrupt
 233   1       CR = 1; // Start PCA counter
 234   1        EA=1;
 235   1       
 236   1      
 237   1      
 238   1      }
 239          
 240          void GetID()                                                                                    //读卡
 241          {
C51 COMPILER V7.50   MAIN                                                                  07/20/2005 09:23:27 PAGE 5   

 242   1              unsigned char i;
 243   1              unsigned long ID;
 244   1      
 245   1                while(buf_p !=128);
 246   1              
 247   1                for(i=0;i<65;i++)
 248   1                {
 249   2                  dat[i]=(dat[i*2]==0) && (dat[i*2+1]==1);
 250   2               
 251   2                }   
 252   1              
 253   1              
 254   1                if( check_emid(dat,iddat ) )
 255   1                {
 256   2                      ID=*(unsigned long*)(iddat+1);                                  //获取的ID号放在iddat中,用一个LONG来表示
 257   2                       putchar(ID);
 258   2                      putchar(ID);
 259   2              }
 260   1               
 261   1       
 262   1                CCAPM4 = 0x21; // Setup module zero in capture mode
 263   1                flag = 0;
 264   1                IE = 0xC0; // Enable PCA interrupt
 265   1                CR = 1; // Start PCA counter
 266   1                EA=1;
 267   1                buf_p=0;
 268   1      
 269   1               
 270   1      
 271   1      }
 272          void main()
 273          {
 274   1      
 275   1      
 276   1       pcaint();
 277   1       while (1) // Software trap
 278   1       {
 279   2        
 280   2              GetID();
 281   2      
 282   2       }
 283   1      }
 284          


MODULE INFORMATION:   STATIC OVERLAYABLE
   CODE SIZE        =    524    ----
   CONSTANT SIZE    =     17    ----
   XDATA SIZE       =   ----    ----
   PDATA SIZE       =   ----    ----
   DATA SIZE        =      8      17
   IDATA SIZE       =    139    ----
   BIT SIZE         =      1    ----
END OF MODULE INFORMATION.


C51 COMPILATION COMPLETE.  0 WARNING(S),  0 ERROR(S)

⌨️ 快捷键说明

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