![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
programme RFID anthony coudret-risso
Dependencies: mbed
Diff: main.cpp
- Revision:
- 0:a8c7cc9e26fb
- Child:
- 1:290a357d0da0
diff -r 000000000000 -r a8c7cc9e26fb main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Wed May 23 12:25:11 2018 +0000 @@ -0,0 +1,203 @@ +#include "stdio.h" +#include "mbed.h" +#include <Serial.h> + +DigitalIn CTS(p8); +DigitalOut led1(LED1); +DigitalOut led2(LED2); +DigitalOut led3(LED3); +DigitalOut led4(LED4); + +Serial pc(USBTX, USBRX); +Serial rfid1(p9, NC); +Serial rfid2(NC, p10); + +int egal1 = 0; +int egal2 = 0; +int egal3 = 0; +int egal4 = 0; +int egal5 = 0; +int tag1[]= {0xAE,0xFB,0x63,0x10}; +int tag2[]= {0x25,0x02,0x64,0x10}; +int tag3[]= {0x3F,0xFC,0x63,0x10}; +int tag4[]= {0xCE,0xEE,0x63,0x10}; +int tag5[]= {0xD6,0xD9,0x63,0x10}; +int tag[]= {0}; +int reponse_rfid[5]; +int reponse_rfid1[255]; +int lireuid[8]= {0x52,0x00}; +//int trame_rfid[8]={0x7A}; +//int tag_rfid[8]={0x76,0x01}; +//int uid[8]={0x55}; + +void HandShake(); +void Antenna(); +void Tag(); + +int main() +{ + + egal1=0; + egal2=0; + egal3=0; + egal4=0; + egal5=0; + + while(1) { + + if (CTS == 0) { + // pc.printf("- [CTS = 0] -"); + // pc.printf("\n\r"); + //HandShake(); + for (int i=0; i<2; i++) { + rfid2.putc(lireuid[i]); + } + wait_ms(25); + for (int e=0; e<1; e++) { + reponse_rfid1[e]=(rfid1.getc()); + led1=1; + } + if (reponse_rfid1[0] == 0xD6) { + for (int i=0; i<2; i++) { + rfid2.putc(lireuid[i]); + led2=1; + } + wait_ms(50); + for (int e=1; e<5; e++) { + reponse_rfid[e]=(rfid1.getc()); + led3=1; + } + /*for(int i=0;i<5;i++){ + tag[i] = {0}; + }*/ + + pc.printf("---------------------------------------"); + pc.printf("\n\r"); + pc.printf("Trame de reponse du PCB en hexa : "); + for (int i=0; i<2; i++) pc.printf("%X ",lireuid[i]); + pc.printf("\n\r"); + pc.printf("Status = %X\n\r",reponse_rfid1[0]); + pc.printf("UID = "); + for (int i=1; i<5; i++) pc.printf("%X ",reponse_rfid[i]); + pc.printf("\n\r"); + pc.printf("---------------------------------------"); + pc.printf("\n\r"); + } else if (reponse_rfid1[0] == 0xC0) { + Tag(); + } + if (reponse_rfid1[0] == 0xE0) { + Antenna(); + } + for(int i=1; i<5; i++) { + tag[i-1] = reponse_rfid[i]; + } + + for(int i=0; i<4; i++) { + if(tag[i] == tag1[i]) { + egal1 = 1; + pc.printf("Tag1 - OK "); + pc.printf("\n\r"); + break; + //pc.printf(tag[i]); + } else if(tag[i] != tag1[i]) { + pc.printf("Tag1 - NOK "); + pc.printf("\n\r"); + egal1 = 0; + break; + //pc.printf(tag[i]); + } + } + for(int i=0; i<4; i++) { + if(tag[i] == tag2[i]) { + egal2 = 1; + pc.printf("Tag2 - OK "); + pc.printf("\n\r"); + break; + //pc.printf(tag[i]); + } else if(tag[i] != tag2[i]) { + pc.printf("Tag2 - NOK "); + pc.printf("\n\r"); + egal2 = 0; + break; + //pc.printf(tag[i]); + } + } + for(int i=0; i<4; i++) { + if(tag[i] == tag3[i]) { + egal3 = 1; + pc.printf("Tag3 - OK "); + pc.printf("\n\r"); + break; + //pc.printf(tag[i]); + } else if(tag[i] != tag3[i]) { + pc.printf("Tag3 - NOK "); + pc.printf("\n\r"); + egal3 = 0; + break; + //pc.printf(tag[i]); + } + } + for(int i=0; i<4; i++) { + if(tag[i] == tag4[i]) { + egal4 = 1; + pc.printf("Tag4 - OK "); + pc.printf("\n\r"); + break; + //pc.printf(tag[i]); + } else if(tag[i] != tag4[i]) { + pc.printf("Tag4 - NOK "); + pc.printf("\n\r"); + egal4 = 0; + break; + //pc.printf(tag[i]); + } + } + for(int i=0; i<4; i++) { + if(tag[i] == tag5[i]) { + egal5 = 1; + pc.printf("Tag5 - OK "); + pc.printf("\n\r"); + break; + //pc.printf(tag[i]); + } else if(tag[i] != tag5[i]) { + pc.printf("Tag5 - NOK "); + pc.printf("\n\r"); + egal5 = 0; + break; + //pc.printf(tag[i]); + } + } + + led1=0; + led2=0; + led3=0; + + wait_ms(850); + } + egal1=0; + egal2=0; + egal3=0; + egal4=0; + egal5=0; + } +} + +/*void HandShake(){ + pc.printf("\n\r"); + pc.printf("CTS IS TO 0"); + pc.printf("\n\r"); +}*/ + +void Antenna() +{ + pc.printf("\n\r"); + pc.printf("ANTENNA NOT DETECTED"); + pc.printf("\n\r"); +} + +void Tag() +{ + pc.printf("\n\r"); + pc.printf("NOT TAG IN FIELD"); + pc.printf("\n\r"); +}