#include "../src/rc522.h" #include #include "../lib/usart/src/usart.h" #include "string.h" #include #define uint8_t unsigned char #define uint unsigned int #define MAX_LEN 16 const int chipSelectPin = 10; const int NRSTPD = 5; uint8_t serNum[5]; uint8_t writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0}; uint8_t sectorKeyA[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}; int main() { usart::init(1000000); printf("Hello"); PORTC |= (1<Anticoll(str); memcpy(serNum, str, 5); if (status == MI_OK) { printf("The card's number is : %x%x%x%x%x%x\n\r", serNum[0], serNum[1], serNum[2], serNum[3], serNum[4]); } // select card, return card capacity RC_size = mfrc522->SelectTag(serNum); if (RC_size != 0) {} if(reader) { // write data card blockAddr = 7; // data block 7 status = mfrc522->Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication if (status == MI_OK) { // write data blockAddr = blockAddr - 3 ; writeDate[15] = writeDate[15] + 1; status = mfrc522->Write(blockAddr, writeDate); if(status == MI_OK) { printf("OK!\n\r"); } } } else { // read card blockAddr = 7; // data block 7 status = mfrc522->Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication if (status == MI_OK) { // read data blockAddr = blockAddr - 3 ; status = mfrc522->Read(blockAddr, str); if (status == MI_OK) { printf("Read from the card ,the data is : \n\r"); for (i=0; i<16; i++) { printf("%x", str[i]); if(writeDate[i] != str[i]) printf("Not equal"); } printf("\n\r"); } } } printf("\n\r\n\n\n"); mfrc522->Halt(); // command card into sleeping mode _delay_ms(1000); } }