Add bin folder. Tidy up main.cpp
This commit is contained in:
parent
1c89ad2ea0
commit
a82a2e2b19
|
@ -1,2 +1,2 @@
|
||||||
.vscode/
|
.vscode/
|
||||||
bin/
|
bin/*
|
||||||
|
|
|
@ -12,20 +12,13 @@ const int NRSTPD = 5;
|
||||||
uchar serNum[5];
|
uchar serNum[5];
|
||||||
uchar writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0};
|
uchar writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||||
|
|
||||||
uchar sectorKeyA[16][16] = {{0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF},
|
uchar sectorKeyA[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},
|
|
||||||
};
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
usart::init(1000000);
|
usart::init(1000000);
|
||||||
printf("Hello");
|
printf("Hello");
|
||||||
MFRC522_Init();
|
PORTC |= (1<<PC6)|(1<<PC7);
|
||||||
while(1) {
|
while(1) {
|
||||||
|
MFRC522_Init();
|
||||||
uchar i;
|
uchar i;
|
||||||
uchar status;
|
uchar status;
|
||||||
uchar str[MAX_LEN];
|
uchar str[MAX_LEN];
|
||||||
|
@ -34,10 +27,7 @@ int main() {
|
||||||
|
|
||||||
|
|
||||||
// searching card, return card type
|
// searching card, return card type
|
||||||
status = MFRC522_Request(PICC_REQIDL, str);
|
while(MFRC522_Request(PICC_REQIDL, str) != MI_OK);
|
||||||
if (status == MI_OK)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
status = MFRC522_Anticoll(str);
|
status = MFRC522_Anticoll(str);
|
||||||
|
@ -57,17 +47,13 @@ int main() {
|
||||||
if (RC_size != 0)
|
if (RC_size != 0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
|
if(PINC & (1<<PC6)) {
|
||||||
// write data card
|
// write data card
|
||||||
blockAddr = 7; // data block 7
|
blockAddr = 7; // data block 7
|
||||||
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA[blockAddr/4], serNum); // authentication
|
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||||
if (status == MI_OK)
|
if (status == MI_OK)
|
||||||
|
|
||||||
{
|
{
|
||||||
// write data
|
|
||||||
status = MFRC522_Write(blockAddr, sectorNewKeyA[blockAddr/4]);
|
|
||||||
printf("set the new card password, and can modify the data of the Sector: ");
|
|
||||||
printf("%i", blockAddr/4);
|
|
||||||
|
|
||||||
// write data
|
// write data
|
||||||
blockAddr = blockAddr - 3 ;
|
blockAddr = blockAddr - 3 ;
|
||||||
status = MFRC522_Write(blockAddr, writeDate);
|
status = MFRC522_Write(blockAddr, writeDate);
|
||||||
|
@ -76,12 +62,10 @@ int main() {
|
||||||
printf("OK!\n\r");
|
printf("OK!\n\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
// read card
|
// read card
|
||||||
blockAddr = 7; // data block 7
|
blockAddr = 7; // data block 7
|
||||||
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr,
|
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||||
|
|
||||||
sectorNewKeyA[blockAddr/4], serNum); // authentication
|
|
||||||
if (status == MI_OK)
|
if (status == MI_OK)
|
||||||
{
|
{
|
||||||
// read data
|
// read data
|
||||||
|
@ -93,10 +77,12 @@ int main() {
|
||||||
for (i=0; i<16; i++)
|
for (i=0; i<16; i++)
|
||||||
{
|
{
|
||||||
printf("%c", str[i]);
|
printf("%c", str[i]);
|
||||||
|
if(writeDate[i] != str[i]) printf("Not equal");
|
||||||
}
|
}
|
||||||
printf("\n\r");
|
printf("\n\r");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
printf("\n\r");
|
printf("\n\r");
|
||||||
MFRC522_Halt(); // command card into sleeping mode
|
MFRC522_Halt(); // command card into sleeping mode
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue