0

以下是我的代码供您参考。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;
}
4

0 回答 0