![](/media/cache/group/mehmet_akif_arvas.jpg.50x50_q85.jpg)
RFID kart okuyucu kullanimi. MFRC522
Dependencies: mbed MFRC522 TextLCD keypad
main.cpp@2:9c36d866ef8d, 2018-12-16 (annotated)
- Committer:
- marvas
- Date:
- Sun Dec 16 10:29:55 2018 +0000
- Revision:
- 2:9c36d866ef8d
- Parent:
- 1:77bee052ac90
hc05 rfid ve keypad kapi guvenlik
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
marvas | 0:911799228106 | 1 | #include "mbed.h" |
marvas | 0:911799228106 | 2 | #include "MFRC522.h" |
marvas | 1:77bee052ac90 | 3 | #include "keypad.h" |
marvas | 1:77bee052ac90 | 4 | #include "TextLCD.h" |
marvas | 1:77bee052ac90 | 5 | #define SPI_MOSI D4 |
marvas | 1:77bee052ac90 | 6 | #define SPI_MISO D5 |
marvas | 1:77bee052ac90 | 7 | #define SPI_SCLK D3 |
marvas | 1:77bee052ac90 | 8 | #define SPI_CS A0//sda pin durumu farketmiyor. |
marvas | 1:77bee052ac90 | 9 | #define MF_RESET A1//sda pin durumu farketmiyor. |
marvas | 1:77bee052ac90 | 10 | char sifre[4],sayac=0; |
marvas | 0:911799228106 | 11 | |
marvas | 1:77bee052ac90 | 12 | Serial pc(USBTX, USBRX); |
marvas | 1:77bee052ac90 | 13 | TextLCD lcd(PB_13, PB_14, PB_15, PB_1, PB_2, PB_12); // rs, e, d4-d7 pin bağlantıları |
marvas | 1:77bee052ac90 | 14 | |
marvas | 1:77bee052ac90 | 15 | char Keytable[] = { '1', '2', '3', 'A', |
marvas | 1:77bee052ac90 | 16 | '4', '5', '6', 'B', |
marvas | 1:77bee052ac90 | 17 | '7', '8', '9', 'C', |
marvas | 1:77bee052ac90 | 18 | '*', '0', '#', 'D' |
marvas | 1:77bee052ac90 | 19 | }; |
marvas | 1:77bee052ac90 | 20 | |
marvas | 1:77bee052ac90 | 21 | uint32_t cbAfterInput(uint32_t index) { |
marvas | 1:77bee052ac90 | 22 | wait_ms(400); |
marvas | 0:911799228106 | 23 | |
marvas | 0:911799228106 | 24 | |
marvas | 1:77bee052ac90 | 25 | sifre[sayac]=Keytable[index]; |
marvas | 1:77bee052ac90 | 26 | lcd.printf("*"); |
marvas | 0:911799228106 | 27 | |
marvas | 1:77bee052ac90 | 28 | if(sayac==3) |
marvas | 1:77bee052ac90 | 29 | { |
marvas | 1:77bee052ac90 | 30 | if(sifre[0]=='4' && sifre[1]=='5' && sifre[2]=='6' && sifre[3]=='B') |
marvas | 1:77bee052ac90 | 31 | { |
marvas | 1:77bee052ac90 | 32 | lcd.cls(); |
marvas | 1:77bee052ac90 | 33 | pc.printf("Giris Basarili \n"); |
marvas | 1:77bee052ac90 | 34 | lcd.printf("Giris Basarili"); |
marvas | 1:77bee052ac90 | 35 | wait(3); |
marvas | 1:77bee052ac90 | 36 | lcd.cls(); |
marvas | 1:77bee052ac90 | 37 | sayac=-1; |
marvas | 1:77bee052ac90 | 38 | for(char x=0;x<4;x++) |
marvas | 1:77bee052ac90 | 39 | { |
marvas | 1:77bee052ac90 | 40 | sifre[x]=0; |
marvas | 1:77bee052ac90 | 41 | } |
marvas | 1:77bee052ac90 | 42 | } |
marvas | 1:77bee052ac90 | 43 | else |
marvas | 1:77bee052ac90 | 44 | { |
marvas | 1:77bee052ac90 | 45 | lcd.cls(); |
marvas | 1:77bee052ac90 | 46 | pc.printf("Giris Basarisiz \n"); |
marvas | 1:77bee052ac90 | 47 | lcd.printf("Giris Basarisiz"); |
marvas | 1:77bee052ac90 | 48 | wait(3); |
marvas | 1:77bee052ac90 | 49 | lcd.cls(); |
marvas | 1:77bee052ac90 | 50 | sayac=-1; |
marvas | 1:77bee052ac90 | 51 | for(char x=0;x<4;x++) |
marvas | 1:77bee052ac90 | 52 | { |
marvas | 1:77bee052ac90 | 53 | sifre[x]=0; |
marvas | 1:77bee052ac90 | 54 | } |
marvas | 1:77bee052ac90 | 55 | } |
marvas | 1:77bee052ac90 | 56 | } |
marvas | 1:77bee052ac90 | 57 | sayac++; |
marvas | 1:77bee052ac90 | 58 | return 0; |
marvas | 1:77bee052ac90 | 59 | } |
marvas | 1:77bee052ac90 | 60 | |
marvas | 0:911799228106 | 61 | MFRC522 RfChip (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET); |
marvas | 0:911799228106 | 62 | |
marvas | 0:911799228106 | 63 | int main(void) { |
marvas | 1:77bee052ac90 | 64 | Keypad keypad(D13, D12, D11, D10, D9, D8, D7, D6); |
marvas | 1:77bee052ac90 | 65 | keypad.CallAfterInput(&cbAfterInput); |
marvas | 1:77bee052ac90 | 66 | keypad.Start(); |
marvas | 0:911799228106 | 67 | pc.baud(250000); |
marvas | 0:911799228106 | 68 | |
marvas | 0:911799228106 | 69 | // Init. RC522 Chip |
marvas | 0:911799228106 | 70 | RfChip.PCD_Init(); |
marvas | 0:911799228106 | 71 | |
marvas | 0:911799228106 | 72 | while (true) { |
marvas | 0:911799228106 | 73 | // Look for new cards |
marvas | 0:911799228106 | 74 | if ( ! RfChip.PICC_IsNewCardPresent()) |
marvas | 0:911799228106 | 75 | { |
marvas | 1:77bee052ac90 | 76 | wait_ms(100); |
marvas | 1:77bee052ac90 | 77 | |
marvas | 0:911799228106 | 78 | continue; |
marvas | 0:911799228106 | 79 | } |
marvas | 1:77bee052ac90 | 80 | |
marvas | 0:911799228106 | 81 | |
marvas | 0:911799228106 | 82 | // Select one of the cards |
marvas | 0:911799228106 | 83 | if ( ! RfChip.PICC_ReadCardSerial()) |
marvas | 0:911799228106 | 84 | { |
marvas | 1:77bee052ac90 | 85 | wait_ms(100); |
marvas | 1:77bee052ac90 | 86 | |
marvas | 0:911799228106 | 87 | continue; |
marvas | 0:911799228106 | 88 | } |
marvas | 0:911799228106 | 89 | |
marvas | 0:911799228106 | 90 | |
marvas | 0:911799228106 | 91 | // Print Card UID |
marvas | 0:911799228106 | 92 | printf("Card UID: "); |
marvas | 0:911799228106 | 93 | for (uint8_t i = 0; i < RfChip.uid.size; i++) |
marvas | 0:911799228106 | 94 | { |
marvas | 1:77bee052ac90 | 95 | pc.printf(" %X", RfChip.uid.uidByte[i]); |
marvas | 1:77bee052ac90 | 96 | |
marvas | 0:911799228106 | 97 | } |
marvas | 0:911799228106 | 98 | printf("\n\r"); |
marvas | 1:77bee052ac90 | 99 | if(RfChip.uid.uidByte[0]==0x76 && RfChip.uid.uidByte[1]==0xEC |
marvas | 1:77bee052ac90 | 100 | && RfChip.uid.uidByte[2]==0xCA && RfChip.uid.uidByte[3]==0x1F) |
marvas | 1:77bee052ac90 | 101 | { |
marvas | 1:77bee052ac90 | 102 | pc.printf("Giris Basarili \n"); |
marvas | 1:77bee052ac90 | 103 | } |
marvas | 0:911799228106 | 104 | // Print Card type |
marvas | 0:911799228106 | 105 | uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); |
marvas | 0:911799228106 | 106 | printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); |
marvas | 1:77bee052ac90 | 107 | wait_ms(500); |
marvas | 0:911799228106 | 108 | } |
marvas | 0:911799228106 | 109 | } |