Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    15
    Rep Power
    0

    18F4520 with IDR 232N RFID reader


    Hi, for one of our projects, we are developing a security system with an RFID reader and a GSM modem. Both using simultaneously with many other components...

    Right now we are having difficulties in programming the RFID reader, IDR 232N, with PIC18F4520.

    We are able to read a number off the reader when a card is scanned, but the number is different from the serial number on the card. All the examples off the net uses PIC16F, but in this case we want to use 18F.

    Hope to find some solutions here.

    Here are the data sheets for the reader:
    http://www.robotshop.com/content/PDF/users-manual-rfid-idr-232n.pdf
    http://www.robotshop.com/content/PDF/detailed-description-pr8-b.pdf

    Here is the code we are using right now.
    Code:
    #include <p18f4520.h>
    #include <system4520.h>
    #include <usart.h>
    #include <stdio.h>
    #include <delays.h>
    
    
    unsigned char uart_rec(void);
    
    unsigned char rfid_door[16]="   RFID Door    ";
    unsigned char security_sys[16]=" Security System";
    unsigned char place_tag[16]=" Place your tag ";
    unsigned char reader[16]=" on the reader  ";
    unsigned char id_no[16]={"ID:             "};
    unsigned char identified[16]="User Identified ";
    unsigned char unidentified[16]="User not found! ";
    unsigned char access_denied[16]="Access DENIED!  ";
    unsigned char opendoor[16]="  DOOR OPENED!  ";
    
    void main(void)
    {
    	unsigned char i, database, cardid1,ID;
    	unsigned char id1[10]={7,0,0,0,6,2,8,0,2,2};
    	unsigned char ID1[16]={"7000628022"};
    	unsigned char data[12];
    	
    	//USART INITIALISATION	
    	OpenUSART(USART_TX_INT_OFF &			//transmit interrupt off
    	USART_RX_INT_ON &				//receive interrupt on
    	USART_ASYNCH_MODE &				//asynchronous mode
    	USART_EIGHT_BIT &				//8-bit data
    	USART_CONT_RX &					//continuous reception
    	USART_BRGH_HIGH,25);				//for baud rate 9600
    
    
    	lcd_init();
    	clear_screen();
    	cursor_set(0,0);
    	WriteS(rfid_door);
    	cursor_set(1,0);
    	WriteS(security_sys);
    	Delay10KTCYx(100);
    
    	while(1)
    	{
    		clear_screen();
    		cursor_set(0,0);
    		WriteS(place_tag);
    		cursor_set(1,0);
    		WriteS(reader);
    
    		for(i=0; i<12; i+=1)
    		{
    			data[i]=uart_rec();
    		}
    		
    		clear_screen();
    		cursor_set(0,0);
    		Write_Decimal(data[i]);
    		Delay10KTCYx(255);
    	}
    }	
    
    
    unsigned char uart_rec(void)			//receive uart value
    {
    	unsigned char rec_data;
    	while(PIR1bits.RCIF==0);		//wait for data
    	rec_data = RCREG;				
    	return rec_data;			//return the data received
    }
  2. #2
  3. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    > unsigned char ID1[16]={"7000628022"};
    Is this the number you expect?

    > Write_Decimal(data[i]);
    Do you see something like 55484848.....

    If you do, then try printing an ASCII string instead of decimalising each character.

    You'll need to append a \0 to data (and allow room for it) if you want to use WriteS
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    the id no is 0000523066
    but when tag placed on the reader,

    if is Write_decimal(data[i]), it gives value of 127230230230166102038230102102

    if is number(data[i]), it gives value of
    7000628022

    why is it like that? It should've display 0000523066.
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    15
    Rep Power
    0
    Hi salem, r.tan is my partner in the project. As she said, the result we get is not in ascii either. So we are really confused about this.
  8. #5
  9. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Well this code (as written) would write garbage
    Code:
    		for(i=0; i<12; i+=1)
    		{
    			data[i]=uart_rec();
    		}
    		
    		clear_screen();
    		cursor_set(0,0);
    		Write_Decimal(data[i]);  //!! what is i here?  it's off the end of your array
    You need another loop like
    Code:
    		cursor_set(0,0);
    		for(i=0; i<6; i+=1)
    		{
    			Write_Decimal(data[i]); 
    			WriteS(",");
    		}
    		cursor_set(1,0);
    		for(i=6; i<12; i+=1)
    		{
    			Write_Decimal(data[i]); 
    			WriteS(",");
    		}



    > USART_RX_INT_ON & //receive interrupt on
    I would also turn this OFF, since you don't have an interrupt handler, and you're polling the port rapidly anyway.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    I've tried the code given but it display
    3 DOOR OPENED
    DOOR OPENED!0

    instead of number.

    #include <p18f4520.h>
    #include <system4520.h>
    #include <usart.h>
    #include <stdio.h>
    #include <delays.h>
    #include <stdlib.h>


    unsigned char uart_rec(void);

    unsigned char rfid_door[16]=" RFID Door ";
    unsigned char security_sys[16]=" Security System";
    unsigned char place_tag[16]=" Place your tag ";
    unsigned char reader[16]=" on the reader ";


    void main(void)
    {
    unsigned char i, database, cardid1, ID, x;
    unsigned char id1[10]={0,0,0,0,5,2,3,0,6,6};
    unsigned char ID1[16]={"0000523066"};
    unsigned char data[12];

    //USART INITIALISATION
    OpenUSART(USART_TX_INT_OFF & //transmit interrupt off
    USART_RX_INT_OFF & //receive interrupt on
    USART_ASYNCH_MODE & //asynchronous mode
    USART_EIGHT_BIT & //8-bit data
    USART_CONT_RX & //continuous reception
    USART_BRGH_HIGH,25); //for baud rate 9600


    lcd_init();
    clear_screen();
    cursor_set(0,0);
    WriteS(rfid_door);
    cursor_set(1,0);
    WriteS(security_sys);
    Delay10KTCYx(100);

    while(1)
    {
    clear_screen();
    cursor_set(0,0);
    WriteS(place_tag);
    cursor_set(1,0);
    WriteS(reader);

    for(i=0; i<12; i+=1)
    {
    data[i]=uart_rec();
    }

    clear_screen();
    cursor_set(0,0);
    for(i=0; i<6; i+=1)
    {
    Write_Decimal(data[i]);
    WriteS(",");
    }
    cursor_set(1,0);
    for(i=6; i<12; i++)
    {
    Write_Decimal(data[i]);
    WriteS(",");
    }
    Delay10KTCYx(255);
    }
    }


    unsigned char uart_rec(void) //receive uart value
    {
    unsigned char rec_data;
    while(PIR1bits.RCIF==0); //wait for data
    rec_data = RCREG;
    return rec_data; //return the data received
    }
  12. #7
  13. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Use [code][/code] tags, like your friend managed to do in post #1

    > 3 DOOR OPENED
    > DOOR OPENED!0
    Well that's really strange, because those strings appear nowhere in your latest code (though they are in the original).

    The code I posted should at least have printed 12 commas, if nothing else.

    Check your compilation and flashing procedure, because it looks to me like you just keep running the old code.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  14. #8
  15. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    I retype it and it gave me gabage value rather than 12 commas
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    unsigned char comma[]=",";

    WriteS(comma) instead of WriteS(","), it still gives all garbage values
  18. #10
  19. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Take a picture (or something).
    Just saying "it's garbage" is no use to anybody.

    It might look like garbage to you, but to me it might look like something I've seen before, which might be enough to tell you what is going on.

    Regarding the baud rate selection -> read this
    > USART_BRGH_HIGH,25); //for baud rate 9600
    It's only 25 if your main clock is 4Mhz.
    If your main clock is something else, then you need to adjust your calculation accordingly.
    There's even a spreadsheet on the link I posted to help you work it out.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    15
    Rep Power
    0
    img685.imageshack.us/img685/3008/imag0188lu.jpg

    Thats what the LCD shows with the latest codes.
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    and it is 4Mhz.
  24. #13
  25. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Mmm, regardless of any USART transmission issues, you should still have seen decimal numbers separated by commas regardless of the data itself.

    The Write_Decimal() seems suspect - do you have the source code for it?
    Or do you have a link to some documentation describing it?

    Try this, do you see an incrementing decimal count on the 2nd line?
    Code:
    	int loop = 0;
    	while(1)
    	{
    		clear_screen();
    		cursor_set(0,0);
    		WriteS(place_tag);
    		cursor_set(1,0);
    		Write_Decimal(loop++);
    		Delay10KTCYx(255);
    	}
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2013
    Posts
    9
    Rep Power
    0
    Code:
    void Write_Decimal(int hex_value)
    {	int t1;
    	t1 = hex_value /100;
    //	if (t1 =! '0')
    	if (!(t1 == '0')){WriteC(getchar(t1));}
    	else{WriteC(' ');}	
    	t1 = ((hex_value%100)/10);
    	WriteC(getchar(t1));
    	t1 =  ((hex_value%100)%10);
    	WriteC(getchar(t1));}
    yes, there is an incrementing decimal count on the 2nd line
  28. #15
  29. Contributed User
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    Jun 2005
    Posts
    4,417
    Rep Power
    1871
    Good!

    http://www.robotshop.com/content/PDF...tion-pr8-b.pdf
    RFID-IDR-232N will read the ID from RFID tag if the
    tag is near enough to RFID Reader. The ID is normal
    ly
    10 digit of number. RFID-IDR-232N will
    automatically send this ID with 1 byte of Start of
    heading (0x01), followed by 10 byte of ASCII
    character (ID) and 1 byte of Start of text (0x02).
    This
    protocol is only valid for RFID-IDR-232N. Different
    types of RFID reader sometimes have different
    protocol.
    If your receive code is working, you should see decimal 1 and 2 respectively, when you do this
    Code:
    cursor_set(1,0);
    Write_Decimal(data[0]);
    WriteC(' ');
    Write_Decimal(data[11]);
    Your serial read code should look like this
    Code:
    // Throw away everything until the SOH char is found
    while ( (data[0]=uart_rec()) != 0x01 ) { }
    // Now read 11 more bytes
    for(i=1; i<12; i+=1)
    {
        data[i]=uart_rec();
    }
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo