programme RFID anthony coudret-risso

Dependencies:   mbed

Committer:
notBED
Date:
Wed May 23 12:25:11 2018 +0000
Revision:
0:a8c7cc9e26fb
Child:
1:290a357d0da0

        

Who changed what in which revision?

UserRevisionLine numberNew contents of line
notBED 0:a8c7cc9e26fb 1 #include "stdio.h"
notBED 0:a8c7cc9e26fb 2 #include "mbed.h"
notBED 0:a8c7cc9e26fb 3 #include <Serial.h>
notBED 0:a8c7cc9e26fb 4
notBED 0:a8c7cc9e26fb 5 DigitalIn CTS(p8);
notBED 0:a8c7cc9e26fb 6 DigitalOut led1(LED1);
notBED 0:a8c7cc9e26fb 7 DigitalOut led2(LED2);
notBED 0:a8c7cc9e26fb 8 DigitalOut led3(LED3);
notBED 0:a8c7cc9e26fb 9 DigitalOut led4(LED4);
notBED 0:a8c7cc9e26fb 10
notBED 0:a8c7cc9e26fb 11 Serial pc(USBTX, USBRX);
notBED 0:a8c7cc9e26fb 12 Serial rfid1(p9, NC);
notBED 0:a8c7cc9e26fb 13 Serial rfid2(NC, p10);
notBED 0:a8c7cc9e26fb 14
notBED 0:a8c7cc9e26fb 15 int egal1 = 0;
notBED 0:a8c7cc9e26fb 16 int egal2 = 0;
notBED 0:a8c7cc9e26fb 17 int egal3 = 0;
notBED 0:a8c7cc9e26fb 18 int egal4 = 0;
notBED 0:a8c7cc9e26fb 19 int egal5 = 0;
notBED 0:a8c7cc9e26fb 20 int tag1[]= {0xAE,0xFB,0x63,0x10};
notBED 0:a8c7cc9e26fb 21 int tag2[]= {0x25,0x02,0x64,0x10};
notBED 0:a8c7cc9e26fb 22 int tag3[]= {0x3F,0xFC,0x63,0x10};
notBED 0:a8c7cc9e26fb 23 int tag4[]= {0xCE,0xEE,0x63,0x10};
notBED 0:a8c7cc9e26fb 24 int tag5[]= {0xD6,0xD9,0x63,0x10};
notBED 0:a8c7cc9e26fb 25 int tag[]= {0};
notBED 0:a8c7cc9e26fb 26 int reponse_rfid[5];
notBED 0:a8c7cc9e26fb 27 int reponse_rfid1[255];
notBED 0:a8c7cc9e26fb 28 int lireuid[8]= {0x52,0x00};
notBED 0:a8c7cc9e26fb 29 //int trame_rfid[8]={0x7A};
notBED 0:a8c7cc9e26fb 30 //int tag_rfid[8]={0x76,0x01};
notBED 0:a8c7cc9e26fb 31 //int uid[8]={0x55};
notBED 0:a8c7cc9e26fb 32
notBED 0:a8c7cc9e26fb 33 void HandShake();
notBED 0:a8c7cc9e26fb 34 void Antenna();
notBED 0:a8c7cc9e26fb 35 void Tag();
notBED 0:a8c7cc9e26fb 36
notBED 0:a8c7cc9e26fb 37 int main()
notBED 0:a8c7cc9e26fb 38 {
notBED 0:a8c7cc9e26fb 39
notBED 0:a8c7cc9e26fb 40 egal1=0;
notBED 0:a8c7cc9e26fb 41 egal2=0;
notBED 0:a8c7cc9e26fb 42 egal3=0;
notBED 0:a8c7cc9e26fb 43 egal4=0;
notBED 0:a8c7cc9e26fb 44 egal5=0;
notBED 0:a8c7cc9e26fb 45
notBED 0:a8c7cc9e26fb 46 while(1) {
notBED 0:a8c7cc9e26fb 47
notBED 0:a8c7cc9e26fb 48 if (CTS == 0) {
notBED 0:a8c7cc9e26fb 49 // pc.printf("- [CTS = 0] -");
notBED 0:a8c7cc9e26fb 50 // pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 51 //HandShake();
notBED 0:a8c7cc9e26fb 52 for (int i=0; i<2; i++) {
notBED 0:a8c7cc9e26fb 53 rfid2.putc(lireuid[i]);
notBED 0:a8c7cc9e26fb 54 }
notBED 0:a8c7cc9e26fb 55 wait_ms(25);
notBED 0:a8c7cc9e26fb 56 for (int e=0; e<1; e++) {
notBED 0:a8c7cc9e26fb 57 reponse_rfid1[e]=(rfid1.getc());
notBED 0:a8c7cc9e26fb 58 led1=1;
notBED 0:a8c7cc9e26fb 59 }
notBED 0:a8c7cc9e26fb 60 if (reponse_rfid1[0] == 0xD6) {
notBED 0:a8c7cc9e26fb 61 for (int i=0; i<2; i++) {
notBED 0:a8c7cc9e26fb 62 rfid2.putc(lireuid[i]);
notBED 0:a8c7cc9e26fb 63 led2=1;
notBED 0:a8c7cc9e26fb 64 }
notBED 0:a8c7cc9e26fb 65 wait_ms(50);
notBED 0:a8c7cc9e26fb 66 for (int e=1; e<5; e++) {
notBED 0:a8c7cc9e26fb 67 reponse_rfid[e]=(rfid1.getc());
notBED 0:a8c7cc9e26fb 68 led3=1;
notBED 0:a8c7cc9e26fb 69 }
notBED 0:a8c7cc9e26fb 70 /*for(int i=0;i<5;i++){
notBED 0:a8c7cc9e26fb 71 tag[i] = {0};
notBED 0:a8c7cc9e26fb 72 }*/
notBED 0:a8c7cc9e26fb 73
notBED 0:a8c7cc9e26fb 74 pc.printf("---------------------------------------");
notBED 0:a8c7cc9e26fb 75 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 76 pc.printf("Trame de reponse du PCB en hexa : ");
notBED 0:a8c7cc9e26fb 77 for (int i=0; i<2; i++) pc.printf("%X ",lireuid[i]);
notBED 0:a8c7cc9e26fb 78 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 79 pc.printf("Status = %X\n\r",reponse_rfid1[0]);
notBED 0:a8c7cc9e26fb 80 pc.printf("UID = ");
notBED 0:a8c7cc9e26fb 81 for (int i=1; i<5; i++) pc.printf("%X ",reponse_rfid[i]);
notBED 0:a8c7cc9e26fb 82 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 83 pc.printf("---------------------------------------");
notBED 0:a8c7cc9e26fb 84 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 85 } else if (reponse_rfid1[0] == 0xC0) {
notBED 0:a8c7cc9e26fb 86 Tag();
notBED 0:a8c7cc9e26fb 87 }
notBED 0:a8c7cc9e26fb 88 if (reponse_rfid1[0] == 0xE0) {
notBED 0:a8c7cc9e26fb 89 Antenna();
notBED 0:a8c7cc9e26fb 90 }
notBED 0:a8c7cc9e26fb 91 for(int i=1; i<5; i++) {
notBED 0:a8c7cc9e26fb 92 tag[i-1] = reponse_rfid[i];
notBED 0:a8c7cc9e26fb 93 }
notBED 0:a8c7cc9e26fb 94
notBED 0:a8c7cc9e26fb 95 for(int i=0; i<4; i++) {
notBED 0:a8c7cc9e26fb 96 if(tag[i] == tag1[i]) {
notBED 0:a8c7cc9e26fb 97 egal1 = 1;
notBED 0:a8c7cc9e26fb 98 pc.printf("Tag1 - OK ");
notBED 0:a8c7cc9e26fb 99 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 100 break;
notBED 0:a8c7cc9e26fb 101 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 102 } else if(tag[i] != tag1[i]) {
notBED 0:a8c7cc9e26fb 103 pc.printf("Tag1 - NOK ");
notBED 0:a8c7cc9e26fb 104 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 105 egal1 = 0;
notBED 0:a8c7cc9e26fb 106 break;
notBED 0:a8c7cc9e26fb 107 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 108 }
notBED 0:a8c7cc9e26fb 109 }
notBED 0:a8c7cc9e26fb 110 for(int i=0; i<4; i++) {
notBED 0:a8c7cc9e26fb 111 if(tag[i] == tag2[i]) {
notBED 0:a8c7cc9e26fb 112 egal2 = 1;
notBED 0:a8c7cc9e26fb 113 pc.printf("Tag2 - OK ");
notBED 0:a8c7cc9e26fb 114 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 115 break;
notBED 0:a8c7cc9e26fb 116 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 117 } else if(tag[i] != tag2[i]) {
notBED 0:a8c7cc9e26fb 118 pc.printf("Tag2 - NOK ");
notBED 0:a8c7cc9e26fb 119 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 120 egal2 = 0;
notBED 0:a8c7cc9e26fb 121 break;
notBED 0:a8c7cc9e26fb 122 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 123 }
notBED 0:a8c7cc9e26fb 124 }
notBED 0:a8c7cc9e26fb 125 for(int i=0; i<4; i++) {
notBED 0:a8c7cc9e26fb 126 if(tag[i] == tag3[i]) {
notBED 0:a8c7cc9e26fb 127 egal3 = 1;
notBED 0:a8c7cc9e26fb 128 pc.printf("Tag3 - OK ");
notBED 0:a8c7cc9e26fb 129 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 130 break;
notBED 0:a8c7cc9e26fb 131 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 132 } else if(tag[i] != tag3[i]) {
notBED 0:a8c7cc9e26fb 133 pc.printf("Tag3 - NOK ");
notBED 0:a8c7cc9e26fb 134 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 135 egal3 = 0;
notBED 0:a8c7cc9e26fb 136 break;
notBED 0:a8c7cc9e26fb 137 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 138 }
notBED 0:a8c7cc9e26fb 139 }
notBED 0:a8c7cc9e26fb 140 for(int i=0; i<4; i++) {
notBED 0:a8c7cc9e26fb 141 if(tag[i] == tag4[i]) {
notBED 0:a8c7cc9e26fb 142 egal4 = 1;
notBED 0:a8c7cc9e26fb 143 pc.printf("Tag4 - OK ");
notBED 0:a8c7cc9e26fb 144 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 145 break;
notBED 0:a8c7cc9e26fb 146 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 147 } else if(tag[i] != tag4[i]) {
notBED 0:a8c7cc9e26fb 148 pc.printf("Tag4 - NOK ");
notBED 0:a8c7cc9e26fb 149 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 150 egal4 = 0;
notBED 0:a8c7cc9e26fb 151 break;
notBED 0:a8c7cc9e26fb 152 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 153 }
notBED 0:a8c7cc9e26fb 154 }
notBED 0:a8c7cc9e26fb 155 for(int i=0; i<4; i++) {
notBED 0:a8c7cc9e26fb 156 if(tag[i] == tag5[i]) {
notBED 0:a8c7cc9e26fb 157 egal5 = 1;
notBED 0:a8c7cc9e26fb 158 pc.printf("Tag5 - OK ");
notBED 0:a8c7cc9e26fb 159 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 160 break;
notBED 0:a8c7cc9e26fb 161 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 162 } else if(tag[i] != tag5[i]) {
notBED 0:a8c7cc9e26fb 163 pc.printf("Tag5 - NOK ");
notBED 0:a8c7cc9e26fb 164 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 165 egal5 = 0;
notBED 0:a8c7cc9e26fb 166 break;
notBED 0:a8c7cc9e26fb 167 //pc.printf(tag[i]);
notBED 0:a8c7cc9e26fb 168 }
notBED 0:a8c7cc9e26fb 169 }
notBED 0:a8c7cc9e26fb 170
notBED 0:a8c7cc9e26fb 171 led1=0;
notBED 0:a8c7cc9e26fb 172 led2=0;
notBED 0:a8c7cc9e26fb 173 led3=0;
notBED 0:a8c7cc9e26fb 174
notBED 0:a8c7cc9e26fb 175 wait_ms(850);
notBED 0:a8c7cc9e26fb 176 }
notBED 0:a8c7cc9e26fb 177 egal1=0;
notBED 0:a8c7cc9e26fb 178 egal2=0;
notBED 0:a8c7cc9e26fb 179 egal3=0;
notBED 0:a8c7cc9e26fb 180 egal4=0;
notBED 0:a8c7cc9e26fb 181 egal5=0;
notBED 0:a8c7cc9e26fb 182 }
notBED 0:a8c7cc9e26fb 183 }
notBED 0:a8c7cc9e26fb 184
notBED 0:a8c7cc9e26fb 185 /*void HandShake(){
notBED 0:a8c7cc9e26fb 186 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 187 pc.printf("CTS IS TO 0");
notBED 0:a8c7cc9e26fb 188 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 189 }*/
notBED 0:a8c7cc9e26fb 190
notBED 0:a8c7cc9e26fb 191 void Antenna()
notBED 0:a8c7cc9e26fb 192 {
notBED 0:a8c7cc9e26fb 193 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 194 pc.printf("ANTENNA NOT DETECTED");
notBED 0:a8c7cc9e26fb 195 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 196 }
notBED 0:a8c7cc9e26fb 197
notBED 0:a8c7cc9e26fb 198 void Tag()
notBED 0:a8c7cc9e26fb 199 {
notBED 0:a8c7cc9e26fb 200 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 201 pc.printf("NOT TAG IN FIELD");
notBED 0:a8c7cc9e26fb 202 pc.printf("\n\r");
notBED 0:a8c7cc9e26fb 203 }