韦根26韦根34

http://baike.baidu.com/view/557637.htm

WG26协议

Wiegand 26 格式:
各数据位的含义:
 1   位: 为输出数据2—13位的偶校验位
2—9 位:  ID卡的HID码的低8位
10-25位:  ID卡的PID号码
 26 位: 为输出数据14-25位的奇校验位
 
数据输出顺序:
     HID码和 PID码均为高位在前,低位在后
例:一张 ID卡内容为:
HID: 32769   PID:34953      ( 卡面印:2147584137   001, 34953 )
相应的二进制为:
HID: 1000 0000 0000 0001       ( 只输出低8位 )
PID: 1000 1000 1000 1001
输出如下:
1 2          9 10                     25  26
0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1     1
   | HID_L   |        PID             |
 
    输出端D0、D1时序:
图示:

(1) D0、 D1在没有数据输出时均保持高电平;
(2) 输出数据位时间为 420uS(TL),如输出为0,D0拉低420uS(TL)后为高电平,若输出为1,则D1拉低420uS(TL)后为高电平;
输出数据位之间的间隔时间为 2mS(TL),如输出00:D0拉低420uS(TL)后为高电2mS(TL),再拉低为低电平420uS(TL),然后释放为高电平;
 
WG34 协议
Wiegand 34 格式:
各数据位的含义:
 1   位: 为输出第2—17位的偶校验位
2-17 位:  ID卡的HID码
18-33位:  ID卡的PID号码
 34 位: 为输出第18-33位的奇校验位
 
数据输出顺序:
     HID码和 PID码均为高位在前,低位在后
例:一张 ID卡内容为:
HID: 32769   PID:34953       ( 卡面印:2147584137   001, 34953 )
相应的二进制为:
HID: 1000 0000 0000 0001
PID: 1000 1000 1000 1001
输出如下:
1 2                      17 18                     33  34
0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 1 0 0 0 1 0 0 1    0
 |        HID_L            |          PID            |
 
输出端D0、D1时序:
 图示:

 韦根26韦根34_第1张图片

(1) D0、 D1在没有数据输出时均保持高电平;
(2) 输出数据位时间为 420uS(TL),如输出为0,D0拉低420uS(TL)后为高电平,若输出为1,则D1拉低420uS(TL)后为高电平;
(3) 输出数据位之间的间隔时间为 2mS(TL),如输出00:D0拉低420uS(TL)后为高电2mS(TL),再拉低为低电平420uS(TL),然后释放为高电平;
 
发送程序如下:
Str[]中存的是4字节卡号。
void Send_Weigand34(unsigned char *str)
{
       unsigned char one_num = 0;
       unsigned char even = 0;
       unsigned char odd = 0;
       unsigned char check_temp,i;
      
       check_temp = *str;
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       check_temp = *(str 1);
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       if(one_num % 2 )
              even = 1;
       else
              even = 0;
 
       one_num = 0;
       check_temp = *(str 2);
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       check_temp = *(str 3);
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       if(one_num % 2 )
              odd = 0;
       else
              odd = 1;
       one_num = 0;
      
       WG_DATA0 = 1;
       WG_DATA1 = 1;
       Delay_1ms(2);
       if(even)
       {
              WG_DATA1 = 0;                    /*偶校验位为1*/
 
              Delay_50us(8);
              WG_DATA1 = 1;
       }
       else
       {           
              WG_DATA0 = 0;                   /*偶校验位为0*/
              Delay_50us(8);
              WG_DATA0 = 1;
       }
      
       Delay_1ms(2);                        /*延时2ms*/
      
       for(i = 0;i < 32;i )
       {
              WG_DATA0 = 1;
              WG_DATA1 = 1;
 
              if(str[0] & 0x80)
              {
                     WG_DATA1 = 0;
                     Delay_50us(8);
                     WG_DATA1 = 1;
              }
              else
              {
                     WG_DATA0 = 0;
                     Delay_50us(8);
                     WG_DATA0 = 1;
              }
              (*(long*)&str[0]) <<= 1;
              Delay_1ms(2);               /*延时2ms*/
       }
       WG_DATA0 = 1;
       WG_DATA1 = 1;
       if(odd)
       {
              WG_DATA1 = 0;
 
              Delay_50us(8);
              WG_DATA1 = 1;
       }
       else
       {           
              WG_DATA0 = 0;
              Delay_50us(8);
              WG_DATA0 = 1;
       }
       Delay_1ms(2);  
}
/*
韦根26发送函数
*/
void Send_Weigand26(unsigned char *str)
{
       unsigned char one_num = 0;
       unsigned char even = 0;
       unsigned char odd = 0;
       unsigned char check_temp,i;
      
       check_temp = *str;
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       check_temp = *(str 1);
       for(i = 0;i < 4;i )
       {
              if(check_temp & 0x80)
                     one_num ;
              check_temp <<= 1;
       }
      
       if(one_num % 2 )
              even = 1;
       else
              even = 0;
 
       one_num = 0;
       check_temp = *(str 1);
       for(i = 0;i < 4;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       check_temp = *(str 2);
       for(i = 0;i < 8;i )
       {
              if(check_temp & 0x01)
                     one_num ;
              check_temp >>= 1;
       }
       if(one_num % 2 )
              odd = 0;
       else
              odd = 1;
       one_num = 0;
      
       WG_DATA0 = 1;
       WG_DATA1 = 1;
       Delay_1ms(2);
       if(even)
       {
              WG_DATA1 = 0;                    /*偶校验位为1*/
 
              Delay_50us(8);
              WG_DATA1 = 1;
       }
       else
       {           
              WG_DATA0 = 0;                   /*偶校验位为0*/
              Delay_50us(8);
              WG_DATA0 = 1;
       }
      
       Delay_1ms(2);                        /*延时2ms*/
      
       for(i = 0;i < 24;i )
       {
              WG_DATA0 = 1;
              WG_DATA1 = 1;
 
              if(str[0] & 0x80)
              {
                     WG_DATA1 = 0;
                     Delay_50us(8);
                     WG_DATA1 = 1;
              }
              else
              {
                     WG_DATA0 = 0;
                     Delay_50us(8);
                     WG_DATA0 = 1;
              }
              (*(long*)&str[0]) <<= 1;
              Delay_1ms(2);               /*延时2ms*/
       }
       WG_DATA0 = 1;
       WG_DATA1 = 1;
       if(odd)
       {
              WG_DATA1 = 0;
 
              Delay_50us(8);
              WG_DATA1 = 1;
       }
       else
       {           
              WG_DATA0 = 0;
              Delay_50us(8);
              WG_DATA0 = 1;
       }
       Delay_1ms(2);  
}

转载于:https://www.cnblogs.com/icedog/p/3281074.html

你可能感兴趣的:(韦根26韦根34)