Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

RFID with Pic16f877A

Status
Not open for further replies.

abdo.medo1000

Member level 1
Joined
Apr 27, 2021
Messages
33
Helped
0
Reputation
0
Reaction score
0
Trophy points
6
Activity points
324
Hi dear all,

I have been working on my school project for couple of weeks and I'm trying to make RFID Door Lock by using Pic16f877A and RDM6300 RFID reader , I made a code works on PROTUS but I interfaced the cards tags as decimal number like(123456) and after that I noticed that all RF cards have HEX value like (B5:CF:79:23)
now I want to store my cards tag in the code and if i put the card on the RFID antenna it should be works if the card its correct
may you guide me to store my card tags on the program (B5:CF:79:23)👏

my code
Code:
sbit LCD_RS at RD2_bit;
sbit LCD_EN at RD3_bit;
sbit LCD_D4 at RD4_bit;
sbit LCD_D5 at RD5_bit;
sbit LCD_D6 at RD6_bit;
sbit LCD_D7 at RD7_bit;

sbit LCD_RS_Direction at TRISD2_bit;
sbit LCD_EN_Direction at TRISD3_bit;
sbit LCD_D4_Direction at TRISD4_bit;
sbit LCD_D5_Direction at TRISD5_bit;
sbit LCD_D6_Direction at TRISD6_bit;
sbit LCD_D7_Direction at TRISD7_bit;
void main()
    {
     unsigned char  i, rfid[13];
     //char String[8]= "B5:CF:79:23";
     int abdo =54321;
     int islam =12345;
     int y;
     Lcd_Init();
     trisc.RC3=0;
     portc.RC3=0;
     portc.RC4=0;
     trisc.RC4=0;
     portc.RC5=0;
     trisc.RC5=0;                     // Initialize LCD
     Lcd_Cmd(_LCD_CLEAR);              // Clear display
     Lcd_Cmd(_LCD_CURSOR_OFF);         // Cursor off
     Lcd_Out(1,1,"RFID Tag Reader");   // Write text in first row
     UART1_Init(9600);                 // Initialize UART, 9600 baud rate
     rfid[12] = '\0';                  // String Terminating Character
       while(1)                        // Infinite Loop
      {
        if (UART1_Data_Ready())        // If UART Data Ready
        {

          for(i=0;i<5;)                // To Read 5 characters
          {
            if (UART1_Data_Ready())
            {
                  rfid[i] = UART1_Read();
                  i++;
            }
          }
          Lcd_Cmd(_LCD_CLEAR);              // Clear display
          Lcd_Cmd(_LCD_CURSOR_OFF);         // Cursor off
          Lcd_Out(1,1,"  << Welcome >>");   // Write text in first row
          Lcd_Cmd(_LCD_SECOND_ROW);
          Lcd_Out_cp("  Card ID:");
          for(i=0;i<5;)
          {
            Lcd_Chr_Cp(rfid[i]);
            UART1_Write(rfid[i]);
            i++;
            delay_us(1000);
          }
            y = atoi(&rfid);
            if( islam == y )
            {
              Lcd_Out(1,1,"  Welcome ISlAM  ");
              portc.RC5 =0;
              portc.RC3 =1;
               if(portc.RC3 =1)
              {
                portc.RC4 =1;
                delay_ms(200);
                portc.RC4 =0;
              }
            }
            else if( abdo == y )
            {
              Lcd_Out(1,1,"  Welcome ABDO  ");
              portc.RC5 =0;
              portc.RC3 =1;
              if(portc.RC3 =1)
              {
                portc.RC4 =1;
                delay_ms(200);
                portc.RC4 =0;
              }
            }
            else
             {
                portc.RC3 =0;
                portc.RC4 =0;
                portc.RC5 =1;
                if(portc.RC5 =1)
                {
                  portc.RC4 =1;
                  delay_ms(600);
                  portc.RC4 =0;

                  delay_ms(200);
                }
                Lcd_Out(1,1,"Check Your Card");
             }
              delay_ms(2000);
        }
        else
        {
          portc.RC3 =0;
          portc.RC4 =0;
          portc.RC5 =1;
          Lcd_Out(1,1,"  << Welcome >>  ");
          Lcd_Cmd(_LCD_SECOND_ROW);
          Lcd_Out(2,2,"Press Your Card  ");
         }
     }
   }
1234.jpg
 

B5:CF:79:23 is a 64-bit number so you either have to break it into four 8-bit values and compare them in turn or alternatively convert them to text characters and compare them as a character string. Converting to characters is probably the easiest to maintain because you can directly read them and copy them into your program.
Otherwise you would have to convert a number like 123456 to 0x0001E240 which is harder to work with.

Brian.
 
B5:CF:79:23 is a 64-bit number so you either have to break it into four 8-bit values and compare them in turn or alternatively convert them to text characters and compare them as a character string. Converting to characters is probably the easiest to maintain because you can directly read them and copy them into your program.
Otherwise you would have to convert a number like 123456 to 0x0001E240 which is harder to work with.

Brian.
thank you sir you helped me a lot of time , I appreciate your effort.
I took the Microcontroller course last month so I'm not very familiar with the all library tools ,

may you show me how to break (B5:CF:79:23) and (B1:CF:23:45) into four 8-bit values and compare them in turn or how could i convert them to text because i tried to convert them by using
Code:
HexToInt
function but it doesn't work with me ,
I'm looking forward for your helping .
 

Firstly, an 'int' will probably only hold 16-bits so it wouldn't be big enough to hold all the digits anyway.

From your schematic I assume the bytes (8-bits) from the RFID reader are arriving at the serial port. The USART only has an 8-bit receive register so they are arriving one byte at a time. I can't find a data sheet for the RDM6300 to see the data format but what I would suggest you do is write a short program to simply display the bytes on the LCD so you can see what they are. They may already be ASCII characters or you may have to convert them if they are binary but once you see what the RFID module is producing it should be easy to see how to store and compare them. Try it and let me know what the actual data from the module is.

Brian.
 
Firstly, an 'int' will probably only hold 16-bits so it wouldn't be big enough to hold all the digits anyway.

From your schematic I assume the bytes (8-bits) from the RFID reader are arriving at the serial port. The USART only has an 8-bit receive register so they are arriving one byte at a time. I can't find a data sheet for the RDM6300 to see the data format but what I would suggest you do is write a short program to simply display the bytes on the LCD so you can see what they are. They may already be ASCII characters or you may have to convert them if they are binary but once you see what the RFID module is producing it should be easy to see how to store and compare them. Try it and let me know what the actual data from the module is.

Brian.
thank you for helping ,
I am trying to make a program to display the bytes on the LCD but it does not working on real life
i do not know what should i do
--- Updated ---

Firstly, an 'int' will probably only hold 16-bits so it wouldn't be big enough to hold all the digits anyway.

From your schematic I assume the bytes (8-bits) from the RFID reader are arriving at the serial port. The USART only has an 8-bit receive register so they are arriving one byte at a time. I can't find a data sheet for the RDM6300 to see the data format but what I would suggest you do is write a short program to simply display the bytes on the LCD so you can see what they are. They may already be ASCII characters or you may have to convert them if they are binary but once you see what the RFID module is producing it should be easy to see how to store and compare them. Try it and let me know what the actual data from the module is.

Brian.
hi Mr Brian.
i did a simple code that shows the cards tag on lcd
tthis is the code :
Code:
sbit LCD_RS at RB4_bit;
sbit LCD_EN at RB5_bit;
sbit LCD_D4 at RB0_bit;
sbit LCD_D5 at RB1_bit;
sbit LCD_D6 at RB2_bit;
sbit LCD_D7 at RB3_bit;

sbit LCD_RS_Direction at TRISB4_bit;
sbit LCD_EN_Direction at TRISB5_bit;
sbit LCD_D4_Direction at TRISB0_bit;
sbit LCD_D5_Direction at TRISB1_bit;
sbit LCD_D6_Direction at TRISB2_bit;
sbit LCD_D7_Direction at TRISB3_bit;

unsigned char byte;

void main()
{
 char i, rfid[13];
 int y;
 Lcd_Init();                       // Initialize LCD
 Lcd_Cmd(_LCD_CLEAR);              // Clear display
 Lcd_Cmd(_LCD_CURSOR_OFF);
 Lcd_Out(1,1,"RFID Tag Reader");   // Write text in first row

 UART1_Init(9600);                 // Initialize UART, 9600 baud rate

 rfid[12] = '\0';                  // String Terminating Character

 while(1)                          // Infinite Loop
 {
   if(UART1_Data_Ready())          // If UART Data Ready
   {
     for(i=0;i<12;)                // To Read 12 characters
     {
       if(UART1_Data_Ready())
       {
         rfid[i] = UART1_Read();
         i++;
       }
     }
     lcd_cmd(_LCD_SECOND_ROW);
     lcd_out_cp("Tag:");
     for(i=3;i<12;)
     {
     lcd_chr_cp(rfid[i]);
     UART1_Write(rfid[i]);
     i++;
     }
     delay_ms(1000);
   }
  
 }
}.


i'm looking forward for your guidance
 

Attachments

  • WhatsApp Image 2021-05-27 at 17.38.47 (1).jpeg
    WhatsApp Image 2021-05-27 at 17.38.47 (1).jpeg
    53.2 KB · Views: 129
  • WhatsApp Image 2021-05-27 at 17.38.47.jpeg
    WhatsApp Image 2021-05-27 at 17.38.47.jpeg
    47.1 KB · Views: 140
  • WhatsApp Image 2021-05-27 at 17.38.48 (2).jpeg
    WhatsApp Image 2021-05-27 at 17.38.48 (2).jpeg
    41.7 KB · Views: 125
  • WhatsApp Image 2021-05-27 at 17.38.48 (1).jpeg
    WhatsApp Image 2021-05-27 at 17.38.48 (1).jpeg
    59.2 KB · Views: 127
  • WhatsApp Image 2021-05-27 at 17.38.48.jpeg
    WhatsApp Image 2021-05-27 at 17.38.48.jpeg
    51.7 KB · Views: 122
Last edited:

I had no luck finding a definitive specification for that module but it seems it outputs 14 bytes, the first being 0x02, then 10 characters of ID, then a two character CRC and finally a 0x03 terminator.
Your code doesn't search for the 0x02 so if a byte is missed, all subsequent card reads will be wrong. A better strategy is to look for 0x02 then reset the index so you always 'frame' the data even if there is an error. Characters 11 and 12 are not part of the ID although they should always be the same for a particular tag.

From what I can see, the reader is already returning hex data as ASCII characters so you should be able to concatenate them to a character string or use 'sprintf' if you capture them into an array first.

See what happens if you modify the code in post #5 like this: ( MikroC doesn't run on my OS so I can't test it for you!)
1. allocate a character string something like this - "char TagID[15] = {0};"
2. read the UART until 0x02 is seen then initialize 'i' to zero.
3. read the next 10 characters to TagID[i++];
4. make TagID = 0 so it adds a terminator to the end of the string.
5. print TagID to the LCD.

Although 'TagID' looks like an array, the command to print it to the LCD should think its a printable string as it only contains ASCII characters and it has a zero terminator.

Brian.
 

I had no luck finding a definitive specification for that module but it seems it outputs 14 bytes, the first being 0x02, then 10 characters of ID, then a two character CRC and finally a 0x03 terminator.
Your code doesn't search for the 0x02 so if a byte is missed, all subsequent card reads will be wrong. A better strategy is to look for 0x02 then reset the index so you always 'frame' the data even if there is an error. Characters 11 and 12 are not part of the ID although they should always be the same for a particular tag.

From what I can see, the reader is already returning hex data as ASCII characters so you should be able to concatenate them to a character string or use 'sprintf' if you capture them into an array first.

See what happens if you modify the code in post #5 like this: ( MikroC doesn't run on my OS so I can't test it for you!)
1. allocate a character string something like this - "char TagID[15] = {0};"
2. read the UART until 0x02 is seen then initialize 'i' to zero.
3. read the next 10 characters to TagID[i++];
4. make TagID = 0 so it adds a terminator to the end of the string.
5. print TagID to the LCD.

Although 'TagID' looks like an array, the command to print it to the LCD should think its a printable string as it only contains ASCII characters and it has a zero terminator.

Brian.
thank you for helping ,

I tried to modify my code but it did not work as you said may you modify it on any C compiler , and why we start reading from 0x02 ,
please explain more
 

If the information I found is correct, the data from the RDM6300 looks like this:
<0x02> < ten ID bytes > <2 byte CRC> <0x03>
The problem with your code is although you count the number of bytes 'i' from the UART, you can't be sure that 'i' is zero before data arrives except for the first time it is used. If a byte is lost it makes all the following bytes fall out of line. If you look for the 0x02 you can be sure the next byte is the first character of the ID. To be absolutely sure, you should also calculate the CRC of the ten ID bytes and compare than with the two sent from the RDM6300 and also check the byte after them is 0x03 but none of that is essential, it just confirms there have been no errors.

Note that 0x02 and 0x03 are not visible characters so if you send them to the LCD they probably won't show anything except maybe a space.

Brian.
 

i could not understand how the tags start with 0x02 but on the LCD it only starts from 0 or 6 as i showed on the photos ,
i also tried to use any library from internet and i found this link
it explains what i have to do but the problem is on the library i added it on mikcoC file locations but the program it is not working
i took this message <169 380 Arguments cannot have explicit memory specificator mfrc522.h>

what should i do how can i compare the tags

* i have RC522 RFID reader and RDM6300 RFID reader.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top