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

📄 wiegand.lst

📁 KEIL C上的门禁控制器源代码
💻 LST
📖 第 1 页 / 共 3 页
字号:
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 1   


C51 COMPILER V7.07, COMPILATION OF MODULE WIEGAND
OBJECT MODULE PLACED IN Wiegand.OBJ
COMPILER INVOKED BY: C:\Keil\C51\BIN\C51.EXE Wiegand.c LARGE OPTIMIZE(9,SPEED) BROWSE DEBUG OBJECTEXTEND

stmt level    source

   1          ///////////////////////////////////////////////////////////////////////////////
   2          //
   3          // 韦根通信基本原理:
   4          //   1位奇校验位+韦根数据(24位/32位)+1位偶校验位
   5          //   数据位发送/接收维持时间100us
   6          //   数据位发送/接收周期为120ms
   7          //////////////////////////////////////////////////////////////////////////////
   8          
   9          #include "Global.h"
  10          
  11          // 全局变量定义
  12          extern data  char  User_id[6];          // 用户编号
  13          extern idata char  wieformat;           // 韦根通信格式
  14          extern data  uchar door_state;          // 门控状态
  15          extern idata uchar decaddr;                     // 设备地址     
  16          extern idata uchar areaaddr;            // 分组地址
  17          
  18          extern data  ulong Wiegand_dat;                 // 韦根通信数据
  19          extern data  uchar Wiecnt_max;                  // 韦根通信长度
  20          extern data  uchar Wgnd_count;                  // 韦根数据位计数
  21          
  22          extern bdata bit recv_end;                              // 韦根接收结束
  23          extern bdata bit W_rec_end;                             // 韦根写记录结束
  24          extern bdata bit Odd;                                   // 韦根校验
  25          extern bdata bit Even;
  26          
  27          extern xdata char  tele_code[12];               // 报警电话号码
  28          
  29          extern data uint  trans_ctr;                    // 发送数据指针
  30          extern data uint  trans_size;                   // 发送数据大小
  31          extern xdata uchar trans_buf[TRANSBUFSIZE];     // 发送数据缓冲区
  32          
  33          ///////////////////////////////////////////////////////////////////////////////
  34          // 100us延迟
  35          ///////////////////////////////////////////////////////////////////////////////
  36          void Delay100us()
  37          {
  38   1              idata uchar i;
  39   1      
  40   1              for(i=0;i<38;i++);
  41   1      }
  42          
  43          ///////////////////////////////////////////////////////////////////////////////
  44          // 韦根数据左移通信
  45          ///////////////////////////////////////////////////////////////////////////////
  46          void Wiegand_rol()
  47          {
  48   1              Wiegand_dat=Wiegand_dat<<1;
  49   1      }
  50          
  51          ///////////////////////////////////////////////////////////////////////////////
  52          // 中断2服务例程
  53          ///////////////////////////////////////////////////////////////////////////////
  54          void int0() interrupt 0 using 1
  55          {
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 2   

  56   1              switch(Wgnd_count)
  57   1              {
  58   2              case 0:
  59   2                      TR1=0;
  60   2                      TF1=0;
  61   2                      TH1=0xf5;
  62   2                      TL1=0x33;                       // 1.5ms
  63   2                      TR1=1;
  64   2                      Even=0;
  65   2                      Wgnd_count++;
  66   2                      break;
  67   2              case 1:
  68   2              case 2:
  69   2              case 3:
  70   2              case 4:
  71   2              case 5:
  72   2              case 6:
  73   2              case 7:
  74   2              case 8:
  75   2              case 9:
  76   2              case 10:
  77   2              case 11:
  78   2              case 12:
  79   2              case 13:
  80   2              case 14:
  81   2              case 15:
  82   2              case 16:
  83   2              case 17:
  84   2              case 18:
  85   2              case 19:
  86   2              case 20:
  87   2              case 21:
  88   2              case 22:
  89   2              case 23:
  90   2              case 24:
  91   2              case 25:
  92   2              case 26:
  93   2              case 27:
  94   2              case 28:
  95   2              case 29:
  96   2              case 30:
  97   2              case 31:
  98   2              case 32:
  99   2                      TR1=0;
 100   2                      TF1=0;
 101   2                      TH1=0xf5;
 102   2                      TL1=0x33;                       // 1.5ms
 103   2                      TR1=1;
 104   2                      Wiegand_rol();
 105   2                      Wgnd_count++;
 106   2                      break;
 107   2              case 33:
 108   2                      TR1=0;
 109   2                      TF1=0;                  // 接收完成
 110   2                      Odd=0;
 111   2                      recv_end=TRUE;
 112   2                      Wgnd_count++;
 113   2                      break;
 114   2              default:
 115   2                      break;
 116   2              }
 117   1      }
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 3   

 118          
 119          ///////////////////////////////////////////////////////////////////////////////
 120          // 中断2服务例程
 121          ///////////////////////////////////////////////////////////////////////////////
 122          void int1() interrupt 2 using 1
 123          {
 124   1              switch(Wgnd_count)
 125   1              {
 126   2              case 0:
 127   2                      TR1=0;
 128   2                      TF1=0;
 129   2                      TH1=0xf5;
 130   2                      TL1=0x33;                       // 1.5ms
 131   2                      TR1=1;
 132   2                      Even=1;
 133   2                      Wgnd_count++;
 134   2                      break;
 135   2              case 1:
 136   2              case 2:
 137   2              case 3:
 138   2              case 4:
 139   2              case 5:
 140   2              case 6:
 141   2              case 7:
 142   2              case 8:
 143   2              case 9:
 144   2              case 10:
 145   2              case 11:
 146   2              case 12:
 147   2              case 13:
 148   2              case 14:
 149   2              case 15:
 150   2              case 16:
 151   2              case 17:
 152   2              case 18:
 153   2              case 19:
 154   2              case 20:
 155   2              case 21:
 156   2              case 22:
 157   2              case 23:
 158   2              case 24:
 159   2              case 25:
 160   2              case 26:
 161   2              case 27:
 162   2              case 28:
 163   2              case 29:
 164   2              case 30:
 165   2              case 31:
 166   2              case 32:
 167   2                      TR1=0;
 168   2                      TF1=0;
 169   2                      TH1=0xf5;
 170   2                      TL1=0x33;                       // 1.5ms
 171   2                      TR1=1;
 172   2                      Wiegand_rol();          // 数据位0
 173   2                      Wiegand_dat|=0x01;      // 接收数据位1
 174   2                      Wgnd_count++;
 175   2                      break;
 176   2              case 33:
 177   2                      TR1=0;
 178   2                      TF1=0;                  // 接收完成
 179   2                      Odd=1;
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 4   

 180   2                      recv_end=TRUE;
 181   2                      Wgnd_count++;
 182   2                      break;
 183   2              default:
 184   2                      break;
 185   2              }
 186   1      }
 187          
 188          ///////////////////////////////////////////////////////////////////////////////
 189          // 韦根通信初始化
 190          ///////////////////////////////////////////////////////////////////////////////
 191          void W_init()
 192          {
 193   1              switch(wieformat)
 194   1              {
 195   2              case 1:
 196   2                      Wiecnt_max=32;          // 自定义格式,自定义34位=1+32+1
 197   2                      break;
 198   2              case 2:
 199   2                      Wiecnt_max=24;          // 标准26位=1+24+1
 200   2                      break;
 201   2              case 3:
 202   2                      Wiecnt_max=32;          // 标准34位=1+32+1
 203   2                      break;
 204   2              default:
 205   2                      break;  
 206   2              }
 207   1      
 208   1              Wiegand_dat=0;
 209   1              Wgnd_count=0;
 210   1              Odd=0;
 211   1              Even=0;
 212   1      
 213   1              TCON|=0x05;
 214   1      
 215   1              EX1=0;                                  // 设置int1中断
 216   1              EX0=0;                                  // 设置int0中断
 217   1      
 218   1              return;
 219   1      }
 220          
 221          ///////////////////////////////////////////////////////////////////////////////
 222          // 偶校验
 223          ///////////////////////////////////////////////////////////////////////////////
 224          bit W_oddchk()
 225          {
 226   1              idata uchar i;
 227   1              idata uchar temp_odd=0;
 228   1              idata uint  tempw=0;
 229   1      
 230   1              switch(wieformat)
 231   1              {
 232   2              case 1: 
 233   2              case 3: 
 234   2                      tempw=Wiegand_dat&0x0ffff;              // 韦根数据
 235   2                      for(i=0;i<16;i++)
 236   2                      {
 237   3                              if(IBIT(tempw,i))temp_odd++;    // 偶计数
 238   3                      }
 239   2                      if(temp_odd&0x01)return FALSE;
 240   2                      else return TRUE;
 241   2                      break;
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 5   

 242   2              case 2:
 243   2                      tempw=Wiegand_dat&0x0fff;
 244   2                      for(i=0;i<12;i++)
 245   2                      {
 246   3                              if(IBIT(tempw,i))temp_odd++;
 247   3                      }
 248   2                      if(temp_odd&0x01)return FALSE;
 249   2                      else return TRUE;
 250   2                      break;
 251   2              default:
 252   2                      break;  
 253   2              }
 254   1      }
 255          
 256          ///////////////////////////////////////////////////////////////////////////////
 257          // 奇校验
 258          ///////////////////////////////////////////////////////////////////////////////
 259          bit W_evenchk()
 260          {
 261   1              idata uchar i;
 262   1              idata uchar temp_even=0;
 263   1              idata uint  tempw=0;
 264   1      
 265   1              switch(wieformat)
 266   1              {
 267   2              case 1: 
 268   2              case 3: 
 269   2                      tempw=(Wiegand_dat>>16)&0x0ffff;        // 韦根数据
 270   2                      for(i=0;i<16;i++)
 271   2                      {
 272   3                              if(IBIT(tempw,i))temp_even++;   // 奇校验
 273   3                      }
 274   2                      if(temp_even&0x01)return TRUE;
 275   2                      else return FALSE;
 276   2                      break;
 277   2              case 2: 
 278   2                      tempw=(Wiegand_dat>>12)&0x0fff;
 279   2                      for(i=0;i<12;i++)
 280   2                      {
 281   3                              if(IBIT(tempw,i))temp_even++;
 282   3                      }
 283   2                      if(temp_even&0x01)return TRUE;
 284   2                      else return FALSE;
 285   2                      break;
 286   2              default:
 287   2                      break;  
 288   2              }
 289   1      }
 290          
 291          ///////////////////////////////////////////////////////////////////////////////
 292          // 韦根数据接收
 293          ///////////////////////////////////////////////////////////////////////////////
 294          void Wiegand_recv()
 295          {
 296   1              idata uchar tempaddr;
 297   1      
 298   1              if(TF1)
 299   1              {
 300   2                      TR1=0;
 301   2                      TF1=0;                  // 接收位超时
 302   2                      recv_end=FALSE;
 303   2                      Wgnd_count=0;
C51 COMPILER V7.07   WIEGAND                                                               09/15/2005 12:05:42 PAGE 6   

 304   2                      Wiegand_dat=0;
 305   2                      Odd=0;
 306   2                      Even=0;
 307   2              }
 308   1      
 309   1              if(recv_end)
 310   1              {
 311   2                      tempaddr=(Wiegand_dat>>16)&0xff;
 312   2                      if(tempaddr==areaaddr)
 313   2                      {
 314   3                              tempaddr=(Wiegand_dat>>8)&0xff;
 315   3                              if(tempaddr==decaddr)
 316   3                              {

⌨️ 快捷键说明

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