00011001 / Mbed 2 deprecated Project1

Dependencies:   mbed

Fork of RFID-RC522 by Thomas Kirchner

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MFRC522.h"
00003 #define MF_RESET    D8
00004 Serial pc(SERIAL_TX, SERIAL_RX);
00005 Serial tu(PA_11, PA_12);
00006 MFRC522    RfChip   (PC_12, PC_11, PC_10, PC_8, MF_RESET);
00007 DigitalOut LedGreen(LED1);
00008 
00009 int main(void) {
00010 
00011   pc.printf("starting...\n");
00012 
00013   RfChip.PCD_Init();
00014 
00015   uint8_t ID[8];
00016   uint8_t ID1[8]={0x3B,0xED,0x13,0x80};//Wan
00017   uint8_t ID2[8]={0x4B,0xA9,0x14,0x80};//Gus
00018   uint8_t ID3[8]={0x5B,0x18,0x12,0x80};//Wisa
00019   uint8_t ID4[8]={0x3B,0x1A,0x12,0x80};//Tew
00020 
00021   while (true) {
00022     LedGreen = 1;
00023     // Look for new cards
00024     if ( ! RfChip.PICC_IsNewCardPresent())
00025     {
00026       wait_ms(500);
00027       continue;
00028     }
00029 
00030     // Select one of the cards
00031     if ( ! RfChip.PICC_ReadCardSerial())
00032     {
00033       wait_ms(500);
00034       continue;
00035     }
00036 
00037     LedGreen = 0;
00038     // Print Card UID
00039 
00040     pc.printf("Card UID: ");
00041     for (uint8_t i = 0; i < RfChip.uid.size; i++)
00042     {
00043       pc.printf(" %X", RfChip.uid.uidByte[i]);
00044       ID[i]=RfChip.uid.uidByte[i];
00045     }
00046     pc.printf("\n\r");
00047     if (ID[0]==ID1[0]&&ID[1]==ID1[1]&&ID[2]==ID1[2]&&ID[3]==ID1[3]){
00048         pc.printf("Wan's Card\n");
00049         tu.printf("G");
00050         }
00051     else if(ID[0]==ID2[0]&&ID[1]==ID2[1]&&ID[2]==ID2[2]&&ID[3]==ID2[3]){
00052         pc.printf("Gus's Card\n");
00053         tu.printf("J");
00054         }
00055     else if(ID[0]==ID3[0]&&ID[1]==ID3[1]&&ID[2]==ID3[2]&&ID[3]==ID3[3]){
00056         pc.printf("Wisa's Card\n");
00057         tu.printf("H");
00058         }
00059     else if(ID[0]==ID4[0]&&ID[1]==ID4[1]&&ID[2]==ID4[2]&&ID[3]==ID4[3]){
00060         pc.printf("Tew's Card\n");
00061         tu.printf("K");
00062         }
00063     else{
00064         return (0);
00065         }
00066   }
00067 }