Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define MAX_BITS 100
- #define WEIGAND_WAIT_TIME 3000
- unsigned char databits[MAX_BITS];
- unsigned char bitCount;
- unsigned char flagDone;
- unsigned long weigand_counter;
- unsigned long facilityCode = 0;
- unsigned long cardCode = 0;
- //----------------------------------------------------------------
- void ISR_INT0()
- {
- bitCount++;
- flagDone = 0;
- weigand_counter = WEIGAND_WAIT_TIME;
- }
- //----------------------------------------------------------------
- void ISR_INT1()
- {
- databits[bitCount] = 1;
- bitCount++;
- flagDone = 0;
- weigand_counter = WEIGAND_WAIT_TIME;
- }
- //----------------------------------------------------------------
- void setup()
- {
- pinMode(13, OUTPUT); // SAIDA DE LED
- pinMode(2, INPUT); // DATA0 (INT0)
- pinMode(3, INPUT); // DATA1 (INT1)
- Serial.begin(9600);
- Serial.println("");
- attachInterrupt(0, ISR_INT0, FALLING);
- attachInterrupt(1, ISR_INT1, FALLING);
- weigand_counter = WEIGAND_WAIT_TIME;
- }
- //----------------------------------------------------------------
- void loop()
- {
- if (!flagDone)
- {
- if (--weigand_counter == 0)
- flagDone = 1;
- }
- // NÃO USAR
- if (bitCount > 0 && flagDone)
- {
- unsigned char i;
- Serial.print("");
- Serial.print("");
- Serial.print("");
- if (bitCount == 35)
- {
- for (i = 2; i < 14; i++)
- {
- facilityCode <<= 1;
- facilityCode |= databits[i];
- }
- for (i = 14; i < 34; i++)
- {
- cardCode <<= 1;
- cardCode |= databits[i];
- }
- printBits();
- }
- else if (bitCount == 26)
- {
- for (i = 1; i < 9; i++)
- {
- facilityCode <<= 1;
- facilityCode |= databits[i];
- }
- // card code = bits 10 to 23
- for (i = 9; i < 25; i++)
- {
- cardCode <<= 1;
- cardCode |= databits[i];
- }
- printBits();
- }
- else
- {
- Serial.println(""); //SEM ESPAÇO
- }
- bitCount = 0;
- facilityCode = 0;
- cardCode = 0;
- for (i = 0; i < MAX_BITS; i++)
- {
- databits[i] = 0;
- }
- }
- }
- // NÃO MOSTAR SEPARAÇÃO
- //----------------------------------------------------------------
- void printBits()
- {
- Serial.print("");
- Serial.print(facilityCode);
- Serial.print("");
- // Serial.println(cardCode);
- String saida = "";
- String minhaStr = (String)cardCode;
- int meuLgh = minhaStr.length();
- for ( int i = 0; i < 5 - meuLgh; i++)
- {
- saida += "0";
- }
- saida += minhaStr;
- Serial.println(saida);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement