SPI,I2C,RTC

Dependencies:   MFRC522_Updated ssd1306_library

Committer:
20172573073
Date:
Thu May 21 04:02:33 2020 +0000
Revision:
11:c996c388d45b
Parent:
10:7e62c3111814
Escaner RF

Who changed what in which revision?

UserRevisionLine numberNew contents of line
andres0705 7:6372f34c11d1 1 #include "mbed.h"
andres0705 9:935f87e2299d 2 #include "MFRC522.h"
andres0705 10:7e62c3111814 3 #include "ssd1306.h"
andres0705 10:7e62c3111814 4
andres0705 10:7e62c3111814 5
andres0705 10:7e62c3111814 6 DigitalOut LedRed (LED2);
andres0705 10:7e62c3111814 7 DigitalOut LedGreen (LED1);
andres0705 10:7e62c3111814 8 SSD1306 lcd (D7,D6);
andres0705 10:7e62c3111814 9 Serial pc(USBTX, USBRX);
andres0705 10:7e62c3111814 10 MFRC522 RfChip (D11, D12, D13, PTE0, D10);
andres0705 10:7e62c3111814 11 Ticker tiempo1;
20172573073 11:c996c388d45b 12 static const char tar[]={0xD7,0x4F,0x88,0x19};
20172573073 11:c996c388d45b 13 static const char llav[]={0x27,0x57,0xC1,0x7B};
20172573073 11:c996c388d45b 14 int q,a,b,h;
20172573073 3:bd37bcc0ec09 15 void conteo()
20172573073 3:bd37bcc0ec09 16 {
andres0705 10:7e62c3111814 17 if(h!=0) {
andres0705 10:7e62c3111814 18 q=q+1;
andres0705 10:7e62c3111814 19 }
20172573073 3:bd37bcc0ec09 20 }
andres0705 10:7e62c3111814 21 int main(void)
20172573073 3:bd37bcc0ec09 22 {
andres0705 10:7e62c3111814 23 tiempo1.attach(&conteo,1);
20172573073 11:c996c388d45b 24 q=1590029272;
andres0705 10:7e62c3111814 25 q=q-((5*60)*60);
andres0705 6:820dac5cdd1e 26 lcd.init();
andres0705 10:7e62c3111814 27 lcd.speed (SSD1306::Fast);
20172573073 3:bd37bcc0ec09 28 lcd.cls();
20172573073 3:bd37bcc0ec09 29 lcd.locate (3,1);
20172573073 5:e86f65d4cdf2 30 lcd.printf ("Escaner RF");
20172573073 5:e86f65d4cdf2 31 lcd.locate (4,1);
20172573073 5:e86f65d4cdf2 32 lcd.printf ("Andres Arevalo");
20172573073 5:e86f65d4cdf2 33 lcd.locate (5,1);
20172573073 5:e86f65d4cdf2 34 lcd.printf ("Andres castano");
20172573073 4:500f1ba2d17a 35 lcd.redraw();
20172573073 5:e86f65d4cdf2 36 wait(3);
andres0705 10:7e62c3111814 37 lcd.cls();
andres0705 10:7e62c3111814 38 RfChip.PCD_Init();
andres0705 10:7e62c3111814 39 h=1;
andres0705 6:820dac5cdd1e 40
andres0705 6:820dac5cdd1e 41 while (true) {
20172573073 11:c996c388d45b 42
andres0705 10:7e62c3111814 43 set_time(q);
andres0705 10:7e62c3111814 44 lcd.locate (1,0);
andres0705 10:7e62c3111814 45 time_t seconds = time(NULL);
andres0705 10:7e62c3111814 46 lcd.printf("fecha %s",ctime(&seconds));
andres0705 6:820dac5cdd1e 47 lcd.redraw();
andres0705 10:7e62c3111814 48
andres0705 10:7e62c3111814 49 LedRed = 1;
andres0705 10:7e62c3111814 50 LedGreen = 1;
20172573073 8:51c5c171bbf6 51 char buffer2[32];
20172573073 8:51c5c171bbf6 52 strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds));
20172573073 8:51c5c171bbf6 53 pc.printf("%s", buffer2);
20172573073 11:c996c388d45b 54
20172573073 8:51c5c171bbf6 55 char buffer1[32];
20172573073 8:51c5c171bbf6 56 strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds));
andres0705 10:7e62c3111814 57 pc.printf(" , %s", buffer1);
20172573073 11:c996c388d45b 58 pc.printf(" , 0 \n\r");
andres0705 10:7e62c3111814 59
andres0705 10:7e62c3111814 60 if ( ! RfChip.PICC_IsNewCardPresent()) {
andres0705 10:7e62c3111814 61 wait_ms(500);
andres0705 10:7e62c3111814 62 continue;
andres0705 10:7e62c3111814 63 }
andres0705 10:7e62c3111814 64
andres0705 10:7e62c3111814 65 LedRed = 0;
andres0705 10:7e62c3111814 66
andres0705 10:7e62c3111814 67 if ( ! RfChip.PICC_ReadCardSerial()) {
andres0705 10:7e62c3111814 68 wait_ms(500);
andres0705 10:7e62c3111814 69 continue;
andres0705 10:7e62c3111814 70 }
andres0705 10:7e62c3111814 71
20172573073 11:c996c388d45b 72 lcd.cls();
20172573073 11:c996c388d45b 73 set_time(q);
20172573073 11:c996c388d45b 74 lcd.locate (1,0);
20172573073 11:c996c388d45b 75 lcd.printf("fecha %s",ctime(&seconds));
20172573073 11:c996c388d45b 76 lcd.redraw();
andres0705 10:7e62c3111814 77
andres0705 10:7e62c3111814 78 LedRed = 1;
andres0705 10:7e62c3111814 79 LedGreen = 0;
20172573073 8:51c5c171bbf6 80
20172573073 11:c996c388d45b 81 a=0;
20172573073 11:c996c388d45b 82 b=0;
20172573073 11:c996c388d45b 83 for (uint8_t i = 0; i < RfChip.uid.size; i++) {
20172573073 11:c996c388d45b 84
20172573073 11:c996c388d45b 85 if(uint8_t (tar[i])==RfChip.uid.uidByte[i]){
20172573073 11:c996c388d45b 86 a=a+1;
20172573073 11:c996c388d45b 87 }else{
20172573073 11:c996c388d45b 88 a=0;
20172573073 11:c996c388d45b 89 }
20172573073 11:c996c388d45b 90 }
20172573073 11:c996c388d45b 91 for (uint8_t i = 0; i < RfChip.uid.size; i++) {
20172573073 11:c996c388d45b 92
20172573073 11:c996c388d45b 93 if(uint8_t (llav[i])==RfChip.uid.uidByte[i]){
20172573073 11:c996c388d45b 94 b=b+1;
20172573073 11:c996c388d45b 95 }else{
20172573073 11:c996c388d45b 96 b=0;
20172573073 11:c996c388d45b 97 }
20172573073 11:c996c388d45b 98 }
andres0705 10:7e62c3111814 99
20172573073 11:c996c388d45b 100 strftime(buffer2, 32, "%m/%d/%y", localtime(&seconds));
andres0705 10:7e62c3111814 101 pc.printf("%s", buffer2);
andres0705 10:7e62c3111814 102 strftime(buffer1, 32, "%H:%M:%S", localtime(&seconds));
andres0705 10:7e62c3111814 103 pc.printf(" , %s", buffer1);
20172573073 11:c996c388d45b 104 pc.printf(" , ");
20172573073 11:c996c388d45b 105
20172573073 11:c996c388d45b 106 lcd.locate (5,1);
20172573073 11:c996c388d45b 107
20172573073 11:c996c388d45b 108 if(a==4){
20172573073 11:c996c388d45b 109
20172573073 11:c996c388d45b 110 lcd.printf("Tarjeta ");
20172573073 11:c996c388d45b 111 pc.printf("1");
20172573073 11:c996c388d45b 112 }else if(b==4){
20172573073 11:c996c388d45b 113 lcd.printf("Lavero ");
20172573073 11:c996c388d45b 114 pc.printf("2");
20172573073 11:c996c388d45b 115 }else{
20172573073 11:c996c388d45b 116 lcd.printf("Sitp ");
20172573073 11:c996c388d45b 117 pc.printf("3");
20172573073 11:c996c388d45b 118 }
20172573073 11:c996c388d45b 119
andres0705 10:7e62c3111814 120 lcd.locate (6,1);
andres0705 10:7e62c3111814 121 for (uint8_t i = 0; i < RfChip.uid.size; i++) {
andres0705 10:7e62c3111814 122 lcd.printf(" %x ", RfChip.uid.uidByte[i]);
20172573073 3:bd37bcc0ec09 123
andres0705 10:7e62c3111814 124 }
andres0705 10:7e62c3111814 125 pc.printf("\n\r");
andres0705 10:7e62c3111814 126 lcd.redraw();
20172573073 0:fbda9e7e9269 127 wait(1);
20172573073 0:fbda9e7e9269 128 }
20172573073 8:51c5c171bbf6 129 }
20172573073 11:c996c388d45b 130