热度 14
2012-12-10 17:01
1485 次阅读|
0 个评论
wiegand26的协议相对简单。 这里不做解释。百事不懂问百度。 采集的思路如下。 把D0,D1分别接到INT0,INT1. 在每个中断程序中运行同一个子程序。 采集出来是6个BYTE; 前2个BYTES变成十进制,是8位卡号的前3位。 后4个BYTES变成10进制,是8位卡号的后5位。 if (INTCONbits.INT0IF) //typedef enum _BOOL { FALSE = 0, TRUE } BOOL; { INTCONbits.INT0IF = 0; Wiegand26_int_recive(FALSE); } if (INTCON3bits.INT1IF) { INTCON3bits.INT1IF = 0; Wiegand26_int_recive(TRUE); } /******************************************* 协议规定,两条数据线在无数据时均为高电平, 如果DATA0为低电平代表数据0,DATA1为低电平代表数据1 (低电平信号低于1V,高电平信号大于4V) *******************************************/ void Wiegand26_int_recive(BOOL Bits01) { static unsigned char WiegandCount = 1; //SerialNumber =WiegandCount; switch(WiegandCount) { case 1: //-----------------------IC_card_HID.bits.b0 = Bits01;第1位为2-13位的偶校验位 ECC.even = Bits01; WiegandCount++; break; //------------------------第2-9位对应与电子卡HID码的低8位 case 2: IC_card_HID.bits.b7 = Bits01; WiegandCount++; break; case 3: IC_card_HID.bits.b6 = Bits01; WiegandCount++; break; case 4: IC_card_HID.bits.b5 = Bits01; WiegandCount++; break; case 5: IC_card_HID.bits.b4 = Bits01; WiegandCount++; break; case 6: IC_card_HID.bits.b3 = Bits01; WiegandCount++; break; case 7: IC_card_HID.bits.b2 = Bits01; WiegandCount++; break; case 8: IC_card_HID.bits.b1 = Bits01; WiegandCount++; break; case 9: IC_card_HID.bits.b0 = Bits01; WiegandCount++; break; //---------------------------------------第10-25位对应电子卡的PID号码 case 10: IC_card_PID.bits.b15 = Bits01; WiegandCount++; break; case 11: IC_card_PID.bits.b14 = Bits01; WiegandCount++; break; case 12: IC_card_PID.bits.b13 = Bits01; WiegandCount++; break; case 13: IC_card_PID.bits.b12 = Bits01; WiegandCount++; break; case 14: IC_card_PID.bits.b11 = Bits01; WiegandCount++; break; case 15: IC_card_PID.bits.b10 = Bits01; WiegandCount++; break; case 16: IC_card_PID.bits.b9 = Bits01; WiegandCount++; break; case 17: IC_card_PID.bits.b8 = Bits01; WiegandCount++; break; case 18: IC_card_PID.bits.b7 = Bits01; WiegandCount++; break; case 19: IC_card_PID.bits.b6 = Bits01; WiegandCount++; break; case 20: IC_card_PID.bits.b5 = Bits01; WiegandCount++; break; case 21: IC_card_PID.bits.b4 = Bits01; WiegandCount++; break; case 22: IC_card_PID.bits.b3 = Bits01; WiegandCount++; break; case 23: IC_card_PID.bits.b2 = Bits01; WiegandCount++; break; case 24: IC_card_PID.bits.b1 = Bits01; WiegandCount++; break; case 25: IC_card_PID.bits.b0 = Bits01; WiegandCount++; break; //--------------第26位为14-25位的奇校验位 case 26: ECC.odd = Bits01; Flags.WiegandOKFlag = 1; //标志接收完成 WiegandCount = 1; break; default: WiegandCount = 1; break; } }