Arduino 错误在令牌之前预期为非限定 id '/'

Arduino error expected unqualified-id before '/' token

本文关键字:id 令牌 错误 Arduino      更新时间:2023-10-16

我正在处理一个项目,并在Arduino IDE中不断收到此错误消息:

"/"令牌之前的预期非限定 ID Arduino突出显示"//数组的最大长度"是问题所在。这是我尝试使用的代码:

    # Include <SPI.h>
# Define uchar unsigned char
# Define uint unsigned int
/ / Maximum length of the array
# Define MAX_LEN 16
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
/ / Set the pin
/ / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / / /
const int chipSelectPin = 10; / / if the control panel for the UNO, 328,168
const int chipSelectPin = 53; / / If the control panel is mega 2560,1280
const int NRSTPD = 5;
/ / MF522 command word
# Define PCD_IDLE 0x00 / / NO action; cancel the current command
# Define PCD_AUTHENT 0x0E / / authentication key
# Define PCD_RECEIVE 0x08 / / receive data
# Define PCD_TRANSMIT 0x04 / / Transmit Data
# Define PCD_TRANSCEIVE 0x0C / / Send and receive data
# Define PCD_RESETPHASE 0x0F / / Reset
# Define PCD_CALCCRC 0x03 / / CRC calculation
/ / Mifare_One card command word
# Define PICC_REQIDL 0x26 / / find the antenna area does not enter hibernation
# Define PICC_REQALL 0x52 / / find all the cards antenna area
# Define PICC_ANTICOLL 0x93 / / anti-collision
# Define PICC_SElECTTAG 0x93 / / election card
# Define PICC_AUTHENT1A 0x60 / / authentication key A
# Define PICC_AUTHENT1B 0x61 / / authentication key B
# Define PICC_READ 0x30 / / Read Block
# Define PICC_WRITE 0xA0 / / write block
# Define PICC_DECREMENT 0xC0 / /
# Define PICC_INCREMENT 0xC1 / /
# Define PICC_RESTORE 0xC2 / / transfer block data to the buffer
# Define PICC_TRANSFER 0xB0 / / save the data in the buffer
# Define PICC_HALT 0x50 / / Sleep
/ / And MF522 communication error code is returned when
# Define MI_OK 0
# Define MI_NOTAGERR 1
# Define MI_ERR 2
/ / ------------------ MFRC522 register ---------------
/ / Page 0: Command and Status
# Define Reserved00 0x00
# Define CommandReg 0x01
# Define CommIEnReg 0x02
# Define DivlEnReg 0x03
# Define CommIrqReg 0x04
# Define DivIrqReg 0x05
# Define ErrorReg 0x06
# Define Status1Reg 0x07
# Define Status2Reg 0x08
# Define FIFODataReg 0x09
# Define FIFOLevelReg 0x0A
# Define WaterLevelReg 0x0B
# Define ControlReg 0x0C
# Define BitFramingReg 0x0D
# Define CollReg 0x0E
# Define Reserved01 0x0F
/ / Page 1: Command
# Define Reserved10 0x10
# Define ModeReg 0x11
# Define TxModeReg 0x12
# Define RxModeReg 0x13
# Define TxControlReg 0x14
# Define TxAutoReg 0x15
# Define TxSelReg 0x16
# Define RxSelReg 0x17
# Define RxThresholdReg 0x18
# Define DemodReg 0x19
# Define Reserved11 0x1A
# Define Reserved12 0x1B
# Define MifareReg 0x1C
# Define Reserved13 0x1D
# Define Reserved14 0x1E
# Define SerialSpeedReg 0x1F
/ / Page 2: CFG
# Define Reserved20 0x20
# Define CRCResultRegM 0x21
# Define CRCResultRegL 0x22
# Define Reserved21 0x23
# Define ModWidthReg 0x24
# Define Reserved22 0x25
# Define RFCfgReg 0x26
# Define GsNReg 0x27
# Define CWGsPReg 0x28
# Define ModGsPReg 0x29
# Define TModeReg 0x2A
# Define TPrescalerReg 0x2B
# Define TReloadRegH 0x2C
# Define TReloadRegL 0x2D
# Define TCounterValueRegH 0x2E
# Define TCounterValueRegL 0x2F
/ / Page 3: TestRegister
# Define Reserved30 0x30
# Define TestSel1Reg 0x31
# Define TestSel2Reg 0x32
# Define TestPinEnReg 0x33
# Define TestPinValueReg 0x34
# Define TestBusReg 0x35
# Define AutoTestReg 0x36
# Define VersionReg 0x37
# Define AnalogTestReg 0x38
# Define TestDAC1Reg 0x39
# Define TestDAC2Reg 0x3A
# Define TestADCReg 0x3B
# Define Reserved31 0x3C
# Define Reserved32 0x3D
# Define Reserved33 0x3E
# Define Reserved34 0x3F
/ / -----------------------------------------------
/ / 4 bytes card serial number, the first 5 bytes for the checksum byte
uchar serNum [5];
uchar writeDate [16] = {'T', 'e', 'n', 'g', '', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0, 0};
/ / Sector A password, 16 sectors, each sector password 6Byte
uchar sectorKeyA [16] [16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};
uchar sectorNewKeyA [16] [16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xff, 0x07, 0x80, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF,
0xff, 0x07, 0x80, 0x69, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
};
void setup () {
Serial.begin (9600); / / RFID reader SOUT pin connected to Serial
RX pin at 2400bps
/ / Start the SPI library:
SPI.begin ();
pinMode (chipSelectPin, OUTPUT); / / Set digital pin 10 as OUTPUT to connect
it to the RFID / ENABLE pin
digitalWrite (chipSelectPin, LOW); / / Activate the RFID reader
pinMode (NRSTPD, OUTPUT); / / Set digital pin 10, Not Reset and
Power-down
digitalWrite (NRSTPD, HIGH);
MFRC522_Init ();
}
void loop ()
{
uchar i, tmp;
uchar status;
uchar str [MAX_LEN];
uchar RC_size;
uchar blockAddr; / / select the operating block addresses 0 to 63
/ / Find the card, back card type
status = MFRC522_Request (PICC_REQIDL, str);
if (status == MI_OK)
{
}
/ / Anti-collision, return card serial number 4 bytes
status = MFRC522_Anticoll (str);
memcpy (serNum, str, 5);
if (status == MI_OK)
{
Serial.println ("The card's number is:");
Serial.print (serNum [0], BIN);
Serial.print (serNum [1], BIN);
Serial.print (serNum [2], BIN);
Serial.print (serNum [3], BIN);
Serial.print (serNum [4], BIN);
Serial.println ("");
}
/ / Election card, return to card capacity
RC_size = MFRC522_SelectTag (serNum);
if (RC_size! = 0)
{}
/ / Write data card
blockAddr = 7; / / data block 7
status = MFRC522_Auth (PICC_AUTHENT1A, blockAddr, sectorKeyA [blockAddr / 4],
serNum); / / Certification
if (status == MI_OK)
{
/ / Write data
status = MFRC522_Write (blockAddr, sectorNewKeyA [blockAddr / 4]);
Serial.print ("set the new card password, and can modify the data of the Sector: ");
Serial.print (blockAddr / 4, DEC);
/ / Write data
blockAddr = blockAddr - 3;
status = MFRC522_Write (blockAddr, writeDate);
if (status == MI_OK)
{
Serial.println ("OK!");
}
}
/ / Reader
blockAddr = 7; / / data block 7
status = MFRC522_Auth (PICC_AUTHENT1A, blockAddr,
sectorNewKeyA [blockAddr / 4], serNum); / / Certification
if (status == MI_OK)
{
/ / Read data
blockAddr = blockAddr - 3;
status = MFRC522_Read (blockAddr, str);
if (status == MI_OK)
{
Serial.println ("Read from the card, the data is:");
for (i = 0; i <16; i + +)
{
Serial.print (str [i]);
}
Serial.println ("");
}
}
Serial.println ("");
MFRC522_Halt (); / / command card into hibernation
}

如果你明白为什么,请尽快告诉我。谢谢。

代码上的每条注释都以/ /开头

标准单行注释以 // 开头(注意不带空格)。这就是错误的原因!

另请注意,#Include#include#Define#define