Nucleo RFID EM18 125KHz low frequency

Dependencies:   mbed

main.cpp

Committer:
shivanandgowdakr
Date:
2018-07-12
Revision:
1:3781e9bf2c47
Parent:
0:1a3020ba8001

File content as of revision 1:3781e9bf2c47:


#include "mbed.h"


Serial RfidUHF(PC_12,PD_2);


unsigned char StopReadCode[5] = {0xa0,0x03,0xa8,0x00,0xb5};//Stop reading the label code
unsigned char ResetCode[5]={0xa0,0x03,0x65,0x00,0xf8};//Reset code
unsigned char StopReadCodeCB[6]={0xe0,0x04,0xa8,0x00,0x00,0x74};//Stop reading code success and return the value
unsigned char ResetCodeCB[6]={0xe4,0x04,0x65,0x00,0x00,0xb3};//Reset code success and return the value
unsigned char data[6]={};

    int main()
    {
         int i;
          int n=1;
          
       
        while(true)
        {
         
          wait(2.0);
              while(n)
              {
                for(i=0; i<5;i++)
                RfidUHF.putc(StopReadCode[i]);
                wait(0.2);
                    if(RfidUHF.readable())
                    {
                      for(i=0;i<6;i++)
                          {
                            data[i]=RfidUHF.getc();
                            wait_ms(1);
                          }
                      for(i=0;i<6;i++)
                          {
                            if(data[i]==StopReadCodeCB[i])
                              n=0;
                            else
                              n=1;
                          }
                    }
                    wait(0.5);
             }
                 
                  n=1;
                  
                  while(n)
                  {
                    for(i=0; i<5;i++)
                    RfidUHF.putc(ResetCode[i]);
                    
                    wait(0.2);
                        if(RfidUHF.readable())
                        {
                              for(i=0;i<6;i++)
                              {
                                data[i]=RfidUHF.getc();
                                wait(1);
                              }
                              for(i=0;i<6;i++)
                              {
                                if(data[i]==ResetCodeCB[i])
                                  n=0;
                                else
                                  n=1;
                              }
                         }
                 wait(0.5);
                } 
        }
    }