už si nevím opravdu rady. Mám čipové karty, která má číslo např. 036105021720059652 to odpovídá kódu v binární podobě: 10000000010001010101001101110010001110110101111100000100. Moje čtečka umí číst 26 bitů. Já pracuji s 20 posledními čísly viz kód níže. Tzn. v tomto případě - 10110101111100000100.... To odpovídá v desítkové soustavě číslu 745220... V případě, že mám číslo: 036071220999837956, což odpovídá: 10000000010001010101001101011010100001100111010000000100. Tak jelikož dvacítkové číslo začíná nulou, tak ještě vezmu 2 bity - tzn. 22 dlouhé císlo: Ne toto: 01111000111000000100 ale toto: 1001111000111000000100. Ovšem více než polovina karet mi pracuje správně a 1/3 ne.. Čte to úplně jiná čísla a já nemohu zjistit proč... Poradil by mi někdo prosím? Viz kód níže.: Upozornuji zkopiroval jsem jen urcité části kodu, jsou tam mozné chyby.. kód se kompiluje správně.. jde čistě jen o převod z binární do 10 soustavy, proč mně prostě občas vyhodí úplně jiné čísla.. když se podívám na výstupu Serial.println (); Úplně dole je kod pro převod z binární do 10 soustavy, mockrát děkuji
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
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}; //Svrcina je posledni
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;
}
void setup() {
pinMode(2, INPUT); // DATA0 (INT0)
pinMode(3, INPUT); // DATA1 (INT1)
Serial.begin(9600);
Serial.println("RFID Readers");
// binds the ISR functions to the falling edge of INTO and INT1
attachInterrupt(0, ISR_INT0, FALLING);
attachInterrupt(1, ISR_INT1, FALLING);
weigand_counter = WEIGAND_WAIT_TIME;
}
void loop()
{
// 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;
}
}
void printBits() {
Serial.print("FC = ");
Serial.print(facilityCode);
Serial.print(", CC = ");
Serial.println(cardCode);
int a = 0;
int b = 0;
Serial.print ("Pocet karet: ");
Serial.println (length_);
for (a; a != length_; a++) {
if (cardCode == card [a]){
Serial.println("Autorizace OK");
Serial.println();