RFID kart okuma uygulamasi

Dependencies:   mbed MFRC522

Committer:
marvas
Date:
Tue Oct 15 07:09:04 2019 +0000
Revision:
0:4d2cf80cd4d6
rfid_kart_okuyucu

Who changed what in which revision?

UserRevisionLine numberNew contents of line
marvas 0:4d2cf80cd4d6 1
marvas 0:4d2cf80cd4d6 2 #include "mbed.h"
marvas 0:4d2cf80cd4d6 3 #include "MFRC522.h"
marvas 0:4d2cf80cd4d6 4
marvas 0:4d2cf80cd4d6 5
marvas 0:4d2cf80cd4d6 6 #define SPI_MOSI D4
marvas 0:4d2cf80cd4d6 7 #define SPI_MISO D5
marvas 0:4d2cf80cd4d6 8 #define SPI_SCLK D6//SCK
marvas 0:4d2cf80cd4d6 9 #define SPI_CS D3//SDA
marvas 0:4d2cf80cd4d6 10 // KL25Z Pin for MFRC522 reset
marvas 0:4d2cf80cd4d6 11 #define MF_RESET D2//Rst pini
marvas 0:4d2cf80cd4d6 12
marvas 0:4d2cf80cd4d6 13 MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
marvas 0:4d2cf80cd4d6 14
marvas 0:4d2cf80cd4d6 15 int main(void) {
marvas 0:4d2cf80cd4d6 16
marvas 0:4d2cf80cd4d6 17
marvas 0:4d2cf80cd4d6 18 // Init. RC522 Chip
marvas 0:4d2cf80cd4d6 19 RfChip.PCD_Init();
marvas 0:4d2cf80cd4d6 20
marvas 0:4d2cf80cd4d6 21 while (true) {
marvas 0:4d2cf80cd4d6 22
marvas 0:4d2cf80cd4d6 23
marvas 0:4d2cf80cd4d6 24 // Look for new cards
marvas 0:4d2cf80cd4d6 25 if ( ! RfChip.PICC_IsNewCardPresent())
marvas 0:4d2cf80cd4d6 26 {
marvas 0:4d2cf80cd4d6 27 wait_ms(500);
marvas 0:4d2cf80cd4d6 28 continue;
marvas 0:4d2cf80cd4d6 29 }
marvas 0:4d2cf80cd4d6 30
marvas 0:4d2cf80cd4d6 31
marvas 0:4d2cf80cd4d6 32 // Select one of the cards
marvas 0:4d2cf80cd4d6 33 if ( ! RfChip.PICC_ReadCardSerial())
marvas 0:4d2cf80cd4d6 34 {
marvas 0:4d2cf80cd4d6 35 wait_ms(500);
marvas 0:4d2cf80cd4d6 36 continue;
marvas 0:4d2cf80cd4d6 37 }
marvas 0:4d2cf80cd4d6 38
marvas 0:4d2cf80cd4d6 39 // Print Card UID
marvas 0:4d2cf80cd4d6 40 printf("Card UID: ");
marvas 0:4d2cf80cd4d6 41 for (uint8_t i = 0; i < RfChip.uid.size; i++)
marvas 0:4d2cf80cd4d6 42 {
marvas 0:4d2cf80cd4d6 43 printf(" %X ", RfChip.uid.uidByte[i]);//Hex kodunu verir
marvas 0:4d2cf80cd4d6 44 }
marvas 0:4d2cf80cd4d6 45 printf("\n\r");
marvas 0:4d2cf80cd4d6 46
marvas 0:4d2cf80cd4d6 47 // Print Card type
marvas 0:4d2cf80cd4d6 48 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak);
marvas 0:4d2cf80cd4d6 49 printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
marvas 0:4d2cf80cd4d6 50 }
marvas 0:4d2cf80cd4d6 51 }