Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed qnode MFRC522 Buffer
main.cpp
00001 #include "mbed.h" 00002 #include "MFRC522.h" 00003 #include "qnode.h" 00004 #include "Buffer.h" 00005 00006 00007 DigitalOut led_3(LED3); 00008 DigitalOut led2(LED2); 00009 DigitalOut LedGreen(LED1); 00010 DigitalOut enable(p19); 00011 Serial pc(USBTX, USBRX); 00012 Serial disp_uno(p9, p10); // tx, rx 00013 MFRC522 RfChip (p5, p6, p7, p8, p21); 00014 circular_buf_t buf; // ---->BUFFER CIRCULAR buf 00015 bool flag1=false; 00016 bool flag2=false; 00017 bool flag3=false; 00018 volatile bool buf1ready=false; 00019 volatile bool buf2ready=false; 00020 00021 00022 void disp_unoTx_isr() 00023 { 00024 enable=0; 00025 } 00026 00027 void disp_unoRx_isr() 00028 { 00029 led2=1; 00030 uint8_t b = disp_uno.getc(); 00031 00032 if(b!=NULL) { 00033 circular_buf_put(&buf, b); 00034 } else { 00035 uint8_t a; 00036 circular_buf_get(&buf,&a); 00037 if(a=='1') { 00038 circular_buf_get(&buf,&a); 00039 if(a=='S') { 00040 flag1=true; 00041 } else if(a=='Y') { 00042 flag2=true; 00043 } else if(a=='N') { 00044 flag3=true; 00045 } 00046 }else 00047 circular_buf_reset(&buf); 00048 00049 } 00050 00051 } 00052 00053 00054 int main() 00055 { 00056 struct Queue *q = createQueue(); 00057 pc.printf("Listo para lectura\n"); 00058 buf.size = 5; 00059 buf.buffer = (uint8_t*) malloc(buf.size); 00060 enable=0; 00061 led2=0; 00062 RfChip.PCD_Init(); 00063 disp_uno.attach(&disp_unoRx_isr,Serial::RxIrq); 00064 disp_uno.attach(&disp_unoTx_isr,Serial::TxIrq); 00065 00066 while(1) { 00067 led2 = !led2; 00068 wait_ms(5); 00069 if ( RfChip.PICC_IsNewCardPresent()) { 00070 led_3=0; 00071 if (RfChip.PICC_ReadCardSerial()) { 00072 LedGreen = 1; 00073 pc.printf("Tarjeta Numero: "); 00074 uint8_t * c = &RfChip.uid.uidByte[0]; 00075 enQueue(q,c); 00076 pc.printf("\n\r"); 00077 wait_ms(200); 00078 } 00079 } 00080 00081 00082 if(flag1==true) { 00083 QNode *c= deQueue(q); 00084 enable=1; 00085 for(int i=0; i<4; i++) { 00086 disp_uno.printf("%02X ",c->uid[i]); 00087 } 00088 enable=1; 00089 disp_uno.putc('\n'); 00090 flag1=false; 00091 } else if(flag2==true) { 00092 //enable=1; 00093 pc.printf("YES\n"); 00094 flag2=false; 00095 } else if(flag3==true) { 00096 //enable=1; 00097 pc.printf("NO\n"); 00098 flag3=false; 00099 } 00100 00101 } 00102 }
Generated on Thu Jul 14 2022 21:59:26 by
1.7.2