Changed to Class renamed files
This commit is contained in:
@@ -2,35 +2,58 @@
|
||||
#include <avr/io.h>
|
||||
#include "../lib/usart/src/usart.h"
|
||||
#include "string.h"
|
||||
#include <util/delay.h>
|
||||
|
||||
#define uchar unsigned char
|
||||
#define uint8_t unsigned char
|
||||
#define uint unsigned int
|
||||
#define MAX_LEN 16
|
||||
const int chipSelectPin = 10;
|
||||
const int NRSTPD = 5;
|
||||
|
||||
uchar serNum[5];
|
||||
uchar writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||
uint8_t serNum[5];
|
||||
uint8_t writeDate[16] ={'T', 'e', 'n', 'g', ' ', 'B', 'o', 0, 0, 0, 0, 0, 0, 0, 0,0};
|
||||
|
||||
uchar sectorKeyA[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
uint8_t sectorKeyA[16] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
|
||||
int main() {
|
||||
usart::init(1000000);
|
||||
printf("Hello");
|
||||
PORTC |= (1<<PC6)|(1<<PC7);
|
||||
MFRC522 *mfrc522;
|
||||
MFRC522 mfrc522_1(PB4, &PORTB, PB2, &PORTB);
|
||||
MFRC522 mfrc522_2(PB3, &PORTB, PB2, &PORTB);
|
||||
printf("%x %x ", &PORTB, &DDRB);
|
||||
printf("%x %x ", &PORTC, &DDRC);
|
||||
int reader;
|
||||
|
||||
while(1) {
|
||||
MFRC522_Init();
|
||||
uchar i;
|
||||
uchar status;
|
||||
uchar str[MAX_LEN];
|
||||
uchar RC_size;
|
||||
uchar blockAddr; //Select the address of the operation 0~63
|
||||
|
||||
uint8_t i;
|
||||
uint8_t status;
|
||||
uint8_t str[MAX_LEN];
|
||||
uint8_t RC_size;
|
||||
uint8_t blockAddr; //Select the address of the operation 0~63
|
||||
|
||||
|
||||
// searching card, return card type
|
||||
while(MFRC522_Request(PICC_REQIDL, str) != MI_OK);
|
||||
while(1) {
|
||||
mfrc522_1.Init();
|
||||
if(mfrc522_1.Request(PICC_REQIDL, str) == MI_OK) {
|
||||
mfrc522 = &mfrc522_1;
|
||||
printf("Reader 1\n\r");
|
||||
reader = 1;
|
||||
break;
|
||||
}
|
||||
mfrc522_2.Init();
|
||||
if(mfrc522_2.Request(PICC_REQIDL, str) == MI_OK) {
|
||||
mfrc522 = &mfrc522_2;
|
||||
printf("Reader 2\n\r");
|
||||
reader = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
status = MFRC522_Anticoll(str);
|
||||
status = mfrc522->Anticoll(str);
|
||||
memcpy(serNum, str, 5);
|
||||
if (status == MI_OK)
|
||||
{
|
||||
@@ -43,20 +66,21 @@ int main() {
|
||||
}
|
||||
|
||||
// select card, return card capacity
|
||||
RC_size = MFRC522_SelectTag(serNum);
|
||||
RC_size = mfrc522->SelectTag(serNum);
|
||||
if (RC_size != 0)
|
||||
{}
|
||||
|
||||
if(PINC & (1<<PC6)) {
|
||||
if(reader) {
|
||||
// write data card
|
||||
blockAddr = 7; // data block 7
|
||||
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||
status = mfrc522->Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||
if (status == MI_OK)
|
||||
|
||||
{
|
||||
// write data
|
||||
blockAddr = blockAddr - 3 ;
|
||||
status = MFRC522_Write(blockAddr, writeDate);
|
||||
writeDate[15] = writeDate[15] + 1;
|
||||
status = mfrc522->Write(blockAddr, writeDate);
|
||||
if(status == MI_OK)
|
||||
{
|
||||
printf("OK!\n\r");
|
||||
@@ -65,26 +89,27 @@ int main() {
|
||||
} else {
|
||||
// read card
|
||||
blockAddr = 7; // data block 7
|
||||
status = MFRC522_Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||
status = mfrc522->Auth(PICC_AUTHENT1A, blockAddr, sectorKeyA, serNum); // authentication
|
||||
if (status == MI_OK)
|
||||
{
|
||||
// read data
|
||||
blockAddr = blockAddr - 3 ;
|
||||
status = MFRC522_Read(blockAddr, str);
|
||||
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("%c", str[i]);
|
||||
printf("%x", str[i]);
|
||||
if(writeDate[i] != str[i]) printf("Not equal");
|
||||
}
|
||||
printf("\n\r");
|
||||
}
|
||||
}
|
||||
}
|
||||
printf("\n\r");
|
||||
MFRC522_Halt(); // command card into sleeping mode
|
||||
printf("\n\r\n\n\n");
|
||||
mfrc522->Halt(); // command card into sleeping mode
|
||||
_delay_ms(1000);
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user