下面是我的代码供您参考。 Rx_Buf包含Rfid_Tag [] []中的两个值之一。我从另一个功能获得价值,我想找到并确认。问题是它不起作用。 Rfid_Tag [] []具有不同的值,即其已损坏。我不确定定义的全局变量是如何被破坏的。我尝试将它声明为const,extern仍然是同样的问题。当我将它作为独立程序运行时它工作得很好,但是当我从main.c调用此函数时它无法正常工作。任何人都可以帮助我。
由于
#define NUMBER_OF_RFID_TAGS 2
#define RFID_DATA_LENGTH 17
unsigned char Rfid_Tag[NUMBER_OF_RFID_TAGS][RFID_DATA_LENGTH]= {
{0x96,0x12,0xf1,0x6e,0xda,0x57,0x98,0x02,0x00,0xe1,0x50,0x00,0x00,0x00,0x00,0x00,0x11},
{0x96,0x72,0xe9,0x6e,0xda,0x2f,0x98,0x02,0x00,0xe1,0x50,0x00,0x00,0x00,0x00,0x00,0x11}
};
int RFID_check(char *Rx_Buf)
{
//unsigned char ucRfidReceivedData[RFID_DATA_LENGTH]= *Rx_Buf; //{0x00,0x01,0x2,0x03,0x04,0x5,0x06,0x07,0x8,0x09,0x0A,0xB,0x0C,0x0D,0xE,0x0F,0x10};
unsigned count = 0;
int found = false;
for(int i = 0; i < NUMBER_OF_RFID_TAGS; i++){
count = 0;
for(int j = 0; j < RFID_DATA_LENGTH; j++){
if(Rfid_Tag[i][j] == Rx_Buf[j]){
count++;
//PORTR.DIR = 0xff;
//PORTR.OUTTGL = 0xff;
}
}
if(count == RFID_DATA_LENGTH){
found = true;
break;
}
}
if(found == true){
PORTR.DIR = 0xff;
PORTR.OUTTGL = 0x0f;
RFID_accept();
}
else{
RFID_error();
PORTR.DIR = 0xff;
PORTR.OUTTGL = 0x00;
}
return 0;
}