1

我正在开发一种基于 RFID 的手持设备,该设备使用户能够在设备上刷卡产品并汇总他们的购买。设置 RFID 标签以显示价格以及在刷卡后将标签添加在一起的代码是什么?

Arduino Uno 有可能吗?到目前为止,这就是我所拥有的,它只是在刷卡后显示 RFID 标签。

int RFIDResetPin = 13;

char tag1[13] = "5000B9A7155B"
char tag2[13] = "5000B9A7155B"
char tag3[13] = "5000B9A7155B"
char tag4[13] = "5000B9A7155B"
char tag5[13] = "5000B9A7155B"

void setup() {
    Serial.begin(9600);  // Connect to the serial port.
}

void loop () {
    byte i = 0;
    byte val = 0;
    byte code[6];
    byte checksum = 0;
    byte bytesread = 0;
    byte tempbyte = 0;

    if(Serial.available() > 0) {
        if((val = Serial.read()) == 2) {  // Check for header
            bytesread = 0;
            while (bytesread < 12) {  // Read 10 digit code + 2 digit checksum
                if( Serial.available() > 0) {
                    val = Serial.read();
                    if((val == 0x0D)||
                       (val == 0x0A)||
                       (val == 0x03)||
                       (val == 0x02)) { // If header or stop bytes before the 10 digit reading.

                        break;  // Stop reading
                    }

                    // Do ASCII/hexadecimal conversion:
                    if ((val >= '0') && (val <= '9')) {
                        val = val - '0';
                    }
                    else
                        if ((val >= 'A') && (val <= 'F')) {
                            val = 10 + val - 'A';
                        }

                    // Every two hex-digits, add byte to code:
                    if (bytesread & 1 == 1) {
                        // Make some space for this hex-digit by
                        // shifting the previous hex-digit with 4 bits to the left:
                        code[bytesread >> 1] = (val | (tempbyte << 4));

                        if (bytesread >> 1 != 5) {             // If we're at the checksum byte,
                            checksum ^= code[bytesread >> 1];  // Calculate the checksum... (XOR)
                        };
                    }
                    else {
                        tempbyte = val;                        // Store the first hex digit first...
                    };

                    bytesread++;                               // Ready to read next digit
                }
            }

            // Output to Serial:

            if (bytesread == 12) {                             // If 12 digit read is complete
                Serial.print("5-byte code: ");
                for (i=0; i<5; i++) {
                    if (code[i] < 16)
                        Serial.print("0");
                    Serial.print(code[i], HEX);
                    Serial.print(" ");
                }
                Serial.println();

                Serial.print("Checksum: ");
                Serial.print(code[5], HEX);
                Serial.println(code[5] == checksum ? " -- passed." : " -- error.");
                Serial.println();
            }
            bytesread = 0;
        }
    }
}
4

0 回答 0