RFID-RC522 LCD 16x2 A1602

Dependencies:   mbed MFRC522 TextLCD

Revision:
4:a4096f4a4615
Parent:
3:4695b8771ac9
Child:
5:6d60fc8516d1
--- a/main.cpp	Sat May 09 15:49:02 2020 +0000
+++ b/main.cpp	Sat May 09 16:30:21 2020 +0000
@@ -49,7 +49,7 @@
 DigitalOut LedRed   (LED_RED);
 DigitalOut LedGreen (LED_GREEN);
 
-Serial     DebugUART(UART_TX, UART_RX);
+//Serial  DebugUART(UART_TX, UART_RX);
 MFRC522    RfChip   (SPI_MOSI, SPI_MISO, SPI_SCLK, SPI_CS, MF_RESET);
 
 /* Local functions */
@@ -73,6 +73,8 @@
  * On success the PICC is halted after dumping the data.
  * For MIFARE Classic the factory default key of 0xFFFFFFFFFFFF is tried.
  */
+//INITIAL TIME
+time_t seconds = time(NULL);
 void DumpToSerial(MFRC522::Uid *uid)
 {
     MFRC522::MIFARE_Key key;
@@ -83,20 +85,27 @@
     //Pablo Muñoz Coronas - 1358297
 
     // UID
-
+        printf("Tarjeta Detectada! Card UID\n\r");
     for (uint8_t i = 0; i < uid->size; i++) {
-   
- 
         
-        //lcd.printf(" %X02", uid->uidByte[i]);
-      
-        lcd.printf(" %X02", uid);
+        printf(" %X02", uid->uidByte[i]);
+        lcd.printf(" %X02", uid->uidByte[i]);
     }
+    
     printf("\n\r");
+    printf("\n\r");
+    
+   
+    
+    char buffer[32];
+    strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
+ 
+    printf(" %s", buffer);
+    
 
     // PICC type
     uint8_t piccType = RfChip.PICC_GetType(uid->sak);
-    printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
+    //printf("PICC Type: %s \n\r", RfChip.PICC_GetTypeName(piccType));
 
 
     // Dump contents
@@ -164,8 +173,8 @@
 
     // Dump sectors, highest address first.
     if (no_of_sectors) {
-        printf("Sector  Block   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  AccessBits \n\r");
-        printf("----------------------------------------------------------------------------------------- \n\r");
+        //printf("Sector  Block   0   1   2   3   4   5   6   7   8   9  10  11  12  13  14  15  AccessBits \n\r");
+        //printf("----------------------------------------------------------------------------------------- \n\r");
         for (uint8_t i = no_of_sectors - 1; i > 0; i--) {
             DumpMifareClassicSectorToSerial(uid, key, i);
         }
@@ -226,19 +235,19 @@
 
         // Sector number - only on first line
         if (isSectorTrailer) {
-            printf("  %2d   ", sector);
+            //printf("  %2d   ", sector);
         } else {
-            printf("       ");
+            //printf("       ");
         }
 
         // Block number
-        printf(" %3d  ", blockAddr);
+        //printf(" %3d  ", blockAddr);
 
         // Establish encrypted communications before reading the first block
         if (isSectorTrailer) {
             status = RfChip.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, firstBlock, key, uid);
             if (status != MFRC522::STATUS_OK) {
-                printf("PCD_Authenticate() failed: %s \r\n", RfChip.GetStatusCodeName(status));
+                //printf("PCD_Authenticate() failed: %s \r\n", RfChip.GetStatusCodeName(status));
                 return;
             }
         }
@@ -247,13 +256,13 @@
         byteCount = sizeof(buffer);
         status = RfChip.MIFARE_Read(blockAddr, buffer, &byteCount);
         if (status != MFRC522::STATUS_OK) {
-            printf("MIFARE_Read() failed: %s \r\n", RfChip.GetStatusCodeName(status));
+            //printf("MIFARE_Read() failed: %s \r\n", RfChip.GetStatusCodeName(status));
             continue;
         }
 
         // Dump data
         for (uint8_t index = 0; index < 16; index++) {
-            printf(" %3d", buffer[index]);
+            //printf(" %3d", buffer[index]);
 //      if ((index % 4) == 3)
 //      {
 //        printf(" ");
@@ -288,22 +297,22 @@
 
         if (firstInGroup) {
             // Print access bits
-            printf("   [ %d %d %d ] ", (g[group] >> 2) & 1, (g[group] >> 1) & 1, (g[group] >> 0) & 1);
+            //printf("   [ %d %d %d ] ", (g[group] >> 2) & 1, (g[group] >> 1) & 1, (g[group] >> 0) & 1);
             if (invertedError) {
-                printf(" Inverted access bits did not match! ");
+                //printf(" Inverted access bits did not match! ");
             }
         }
 
         if (group != 3 && (g[group] == 1 || g[group] == 6)) {
             // Not a sector trailer, a value block
-            printf(" Addr = 0x%02X, Value = 0x%02X%02X%02X%02X", buffer[12],
-                   buffer[3],
-                   buffer[2],
-                   buffer[1],
-                   buffer[0]);
+            //printf(" Addr = 0x%02X, Value = 0x%02X%02X%02X%02X", buffer[12],
+                   //buffer[3],
+                   //buffer[2],
+                   //buffer[1],
+                   //buffer[0]);
         }
 
-        printf("\n\r");
+        //printf("\n\r");
     }
 
     return;
@@ -319,27 +328,27 @@
     uint8_t buffer[18];
     uint8_t i;
 
-    printf("Page   0  1  2  3");
+    //printf("Page   0  1  2  3");
     // Try the mpages of the original Ultralight. Ultralight C has more pages.
     for (uint8_t page = 0; page < 16; page +=4) {
         // Read pages
         byteCount = sizeof(buffer);
         status = RfChip.MIFARE_Read(page, buffer, &byteCount);
         if (status != MFRC522::STATUS_OK) {
-            printf("MIFARE_Read() failed: %s \n\r", RfChip.GetStatusCodeName(status));
+            //printf("MIFARE_Read() failed: %s \n\r", RfChip.GetStatusCodeName(status));
             break;
         }
 
         // Dump data
         for (uint8_t offset = 0; offset < 4; offset++) {
             i = page + offset;
-            printf(" %2d  ", i); // Pad with spaces
+            //printf(" %2d  ", i); // Pad with spaces
             for (uint8_t index = 0; index < 4; index++) {
                 i = 4 * offset + index;
-                printf(" %02X ", buffer[i]);
+                //printf(" %02X ", buffer[i]);
             }
 
-            printf("\n\r");
+            //printf("\n\r");
         }
     }
 } // End PICC_DumpMifareUltralightToSerial()
@@ -347,8 +356,8 @@
 int main()
 {
     /* Set debug UART speed */
-    printf("\n\rUART 115200 baud\n\r");
-    DebugUART.baud(115200);
+    //printf("\n\rUART 115200 baud\n\r");
+    //DebugUART.baud(115200);
     printf("\n\r%s %s\n\r",VERSION,CIBLE);
 
     /* Init. RC522 Chip */