韋根26韋根34

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

WG26協議spa

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時序:
 圖示:

 

(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);  
}
相關文章
相關標籤/搜索