kapi guvenlik uygulamasi(RFID,KEypad,LCD,BUZZER,ROLE)
Dependencies: mbed MFRC522 TextLCD keypad
main.cpp
00001 #include "mbed.h" 00002 #include "TextLCD.h" 00003 #include "Keypad.h" 00004 #include <iostream> 00005 #include "MFRC522.h" 00006 00007 Serial pc(USBTX,USBRX); 00008 //KL25Z Pins for MFRC522 SPI interface 00009 #define SPI_MOSI PA_7 //Master output slave input 00010 #define SPI_MISO PA_6 //Master input slave Output 00011 #define SPI_SCLK PA_5 //SCK Clock pulse saat darbesi 00012 #define SPI_CS PB_6 //SDA data pini 00013 // KL25Z Pin for MFRC522 reset 00014 #define MF_RESET PC_7 //RST 00015 00016 MFRC522 RfChip(SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET); 00017 DigitalOut bzr(PB_7); 00018 DigitalOut role(PA_5); 00019 char sifre[4]; 00020 uint8_t sayac=0; 00021 uint8_t hata=3; 00022 char basilantus; 00023 TextLCD lcd(PB_0,PA_4,PC_3,PC_2,PB_3,PA_10); 00024 Keypad key(PC_12, PC_10, PC_11,PD_2,PA_13,PA_14,PA_15,PC_8); 00025 char key_table[] = { 00026 '1', '2', '3', 'A', 00027 '4', '5', '6', 'B', 00028 '7', '8', '9', 'C', 00029 '*', '0', '#', 'D' 00030 }; 00031 00032 void hatametodu() 00033 { 00034 00035 lcd.cls(); 00036 bzr=0; 00037 role=0; 00038 lcd.printf("Giris basarisiz"); 00039 for(uint8_t x=0; x<20; x++) { 00040 bzr=1; 00041 wait_ms(50); 00042 bzr=0; 00043 wait_ms(10); 00044 } 00045 hata--; 00046 if(hata==0) { 00047 lcd.cls(); 00048 hata=3; 00049 for(uint8_t sure=10; sure>0; sure--) { 00050 lcd.locate(0,0); 00051 lcd.printf("%d",sure); 00052 lcd.printf(" "); 00053 wait(1); 00054 } 00055 00056 } 00057 lcd.cls(); 00058 } 00059 00060 int main() 00061 { 00062 pc.baud(9600); 00063 // Init. RC522 Chip 00064 RfChip.PCD_Init(); 00065 uint32_t key_num; 00066 while(true) { 00067 00068 while ((key_num = key.read()) != 0) { 00069 bzr=1; 00070 wait_ms(10); 00071 bzr=0; 00072 sifre[sayac]=*(key_table + key_num-1); 00073 sayac++; 00074 lcd.printf("*"); 00075 cout<<*(key_table + key_num-1)<<endl; 00076 if(sayac==4) { 00077 sayac=0; 00078 if(sifre[0]=='1' && sifre[1]=='2' && sifre[2]=='3' && sifre[3]=='A') { 00079 role=1; 00080 hata=3; 00081 lcd.cls(); 00082 lcd.printf("Giris basarili"); 00083 wait(3); 00084 role=0; 00085 lcd.cls(); 00086 } else { 00087 hatametodu(); 00088 } 00089 lcd.cls(); 00090 }//if(sayac==4) { 00091 00092 }// while ((key_num = key.read()) != 0) { 00093 00094 // Look for new cards 00095 if (RfChip.PICC_IsNewCardPresent()) { 00096 wait_ms(10); 00097 continue; 00098 } 00099 00100 00101 00102 // Select one of the cards 00103 if ( ! RfChip.PICC_ReadCardSerial()) { 00104 wait_ms(10); 00105 continue; 00106 } 00107 00108 // Print Card UID 00109 printf("Kart ID: "); 00110 for (uint8_t i = 0; i < RfChip.uid.size; i++) { 00111 pc.printf(" %X", RfChip.uid.uidByte[i]); 00112 } 00113 pc.printf("\n"); 00114 00115 //kendi kartınızı id'si olacak 00116 if(RfChip.uid.uidByte[0]==0x76 && RfChip.uid.uidByte[1]==0x45 && RfChip.uid.uidByte[2]==0x55 && RfChip.uid.uidByte[3]==0xF5) { 00117 hata=3; 00118 bzr=1; 00119 lcd.cls(); 00120 lcd.printf("Hosgeldiniz Ayse"); 00121 wait(2); 00122 bzr=0; 00123 lcd.cls(); 00124 } else { 00125 hatametodu(); 00126 } 00127 00128 00129 // Print Card type 00130 uint8_t piccType = RfChip.PICC_GetType(RfChip.uid.sak); 00131 pc.printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType)); 00132 00133 }// while(true) { 00134 00135 00136 }//main
Generated on Wed Jul 13 2022 11:48:38 by
1.7.2
Marvas