Před tím mně na číslo v bitové formě - 10000000001100010111100001100010000101000110001000000100
Vylezlo číslo v desítkové podobě - 1335812 (bylo čteno číslo - posledních 0101000110001000000100) což odpovídá - čtečka čte 26 bitů. Nyní bez jakékoliv změny je mi dáváno číslo 2858491 a já nevím proč... Čtečku doma nemám, tak jsem zkoušel několikáté úpravy kódu a vždy dostávám jiná čísla: Originální kód:
Kód: Vybrat vše
#define MAX_BITS 100 // max number of bits
#define WEIGAND_WAIT_TIME 1 // time to wait for another weigand pulse.
unsigned char databits[MAX_BITS]; // stores all of the data bits
unsigned char bitCount; // number of bits currently captured
unsigned char flagDone; // goes low when data is currently being captured
unsigned int weigand_counter; // countdown until we assume there are no more bits
unsigned long facilityCode=0; // decoded facility code
unsigned long cardCode=0; // decoded card code
LiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7,3, POSITIVE); // Initialize LCD Display at address 0x27
char array1[] = " Schvaleno "; //the string to print on the LCD
int tim = 100; //the value of delay time
char array2[] = " Priloz kartu! "; //the string to print on the LCD
char array3[]=" Pocet minut: ";
unsigned long int card [116] = {729092, 422916, 675332, 2592260, 2529284, 1069572, 147972, 737540, 268804, 1005828, 745220, 104964, 483844, 672004, 920068, 419076, 489732, 341764, 349956, 553732, 619524, 2325252, 1335812, 591364, 759300, 358916, 1017348, 814340, 161284, 539652, 607236, 1448708, 865028, 541956, 2052, 886788, 811780, 472068, 825092, 822788, 742148, 934660, 3151876, 1541636, 530948, 870660, 1459716, 3608068, 665092, 798468, 788996, 3379972, 726532, 1535236, 1443844, 934916, 1008388, 741892, 742148, 822020, 404740, 2828036, 3561988, 3238148, 1189636, 605188, 22532, 2592772, 1058820, 610308, 673540, 1068548, 350980, 2249732, 3501828, 740100, 3479556, 865796, 3547396, 541444, 1199620, 804612, 932868, 1443588, 620804, 1003780, 3173380, 3490564, 744708, 3500548, 798724, 824580, 157444, 204804, 544260, 552708, 2328324 , 756228, 592388, 1467652, 1008644, 612356, 2394372, 1393412, 952324, 821508, 1513988, 738308, 2591748, 665092, 2312964, 544772, 724228, 161796, 3376900};
unsigned int pocet [116] = {};
int length_ = sizeof(card) / sizeof(card[0]);
unsigned int z [116] = {40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40, 40,40, 40, 40, 40, 40, 40, 40, 40, 40}; // time to cards
byte o = 0;
int k = 0;
int cteni = HIGH;
int BEEP_BEEP = 25;
int LED_RED = 53;
int LED_YELLOW = 52;
int LED_BLUE = 50;
int vyp = 6;
int p = 0;
// interrupt that happens when INTO goes low (0 bit)
void ISR_INT0() {
//Serial.print("0"); // uncomment this line to display raw binary
bitCount++;
flagDone = 0;
weigand_counter = WEIGAND_WAIT_TIME;
}
// interrupt that happens when INT1 goes low (1 bit)
void ISR_INT1() {
//Serial.print("1"); // uncomment this line to display raw binary
databits[bitCount] = 1;
bitCount++;
flagDone = 0;
weigand_counter = WEIGAND_WAIT_TIME;
}
// This waits to make sure that there have been no more data pulses before processing data
if (!flagDone) {
if (--weigand_counter == 0)
flagDone = 1;
}
// if we have bits and we the weigand counter went out
if (bitCount > 0 && flagDone) {
unsigned char i;
Serial.print("Read ");
Serial.println(bitCount);
Serial.print(" bits. ");
if (bitCount == 35) {
// 35 bit HID Corporate 1000 format
// facility code = bits 2 to 14
for (i=2; i<14; i++) {
facilityCode <<=1;
facilityCode |= databits[i];
}
Serial.println (facilityCode);
// card code = bits 15 to 34
for (i=14; i<34; i++) {
cardCode <<=1;
cardCode |= databits[i];
}
h = 1;
printBits();
}
else if (bitCount == 26) {
// standard 26 bit format
// facility code = bits 2 to 9
for (i=1; i<9; i++) {
facilityCode <<=1;
facilityCode |= databits[i];
}
Serial.println (facilityCode);
// card code = bits 10 to 23
for (i=3; i<25; i++) {
cardCode <<=1;
cardCode |= databits[i];
}
printBits();
}
else {
// you can add other formats if you want!
// Serial.println("Unable to decode.");
}
// cleanup and get ready for the next card
bitCount = 0;
facilityCode = 0;
cardCode = 0;
for (i=0; i<MAX_BITS; i++)
{
databits[i] = 0;
}
}
kod s úpravami - nemám čtečku doma.. zkouším zadat číslo abych viděl výstup na serial lince: Když nyní zadám do charu číslo - 0101000110001000000100 tak mi vyleze na výstupu číslo: 134217632 ¨
část kodu:
Kód: Vybrat vše
unsigned char databits[MAX_BITS] = {'0','1','0','1','0','0','0','1','1','0','0','0','1','0','0','0','0','0','0','1','0','0'}; // stores all of the data bits
unsigned char bitCount = 26; // number of bits currently captured
unsigned char flagDone; // goes low when data is currently being captured
unsigned int weigand_counter; // countdown until we assume there are no more bits
unsigned long facilityCode= 0; // decoded facility code
unsigned long cardCode=0; // decoded card code
Kód: Vybrat vše
Read 26
bits. 8179
Databits: 49
CARDCODE: 49
Databits: 48
CARDCODE: 114
Databits: 48
CARDCODE: 244
Databits: 48
CARDCODE: 504
Databits: 49
CARDCODE: 1009
Databits: 49
CARDCODE: 2035
Databits: 48
CARDCODE: 4086
Databits: 48
CARDCODE: 8188
Databits: 48
CARDCODE: 16376
Databits: 49
CARDCODE: 32753
Databits: 48
CARDCODE: 65522
Databits: 48
CARDCODE: 131060
Databits: 48
CARDCODE: 262136
Databits: 48
CARDCODE: 524272
Databits: 48
CARDCODE: 1048560
Databits: 48
CARDCODE: 2097136
Databits: 49
CARDCODE: 4194289
Databits: 48
CARDCODE: 8388594
Databits: 48
CARDCODE: 16777204
Databits: 0
CARDCODE: 33554408
Databits: 0
CARDCODE: 67108816
Databits: 0
CARDCODE: 134217632
FC = 8179, CC = 134217632
Pocet karet: 215