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 Project Help, problem in C source code

Status
Not open for further replies.

Carnal

Newbie level 3
Joined
Feb 7, 2008
Messages
4
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Activity points
1,309
RFID Project Help

I am doing a project using the parallax 125 Khz RFID reader and I need some help with the code to compare the tag data to the data stored in memory. I am using the PIC18F458 with the CCS compiler. I am using strcmp to compare the two values, but it automatically goes to the else statement I have. Here is what I have for the RFID portion of the project:
Code:
#include <18F458.h>
#include <stdlib.h>

#fuses NOWDT
#fuses HS
#fuses NOOSCSEN
#fuses BROWNOUT
#fuses BORV27
#fuses NOPUT
#fuses DEBUG
#fuses NOLVP

#use delay (clock=10M)
#use rs232 (baud=2400,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8)

#include <stdlib.h>
#include <string.h>


char readin[11]="1100B8E8D1";          //RFID Tag ID
char check[11];
int length, h;

void rx()
{
int i;

	length=strlen(readin);
	
	for(i=0;i<length;i++)
	{
		check[i]=getc();
	}

	if(strcmp(readin, check) == 0)
	{
		output_high(PIN_D0);
		delay_ms(500);
		output_low(PIN_D0);
		delay_ms(500);
		h=1;
	}
	else{
		output_high(PIN_C3);
		delay_ms(500);
		output_low(PIN_C3);
		delay_ms(500);
		h=0;
	}
return;
}


void main(void)
{
	while(TRUE)
	{
	while(input(mode)==automatic)
		{
		if(kbhit())
		{
		rx();
			if(h==1){
				auto_up();
				delay_ms(5000);
				auto_down();
				delay_ms(500);
				h=0;
					}
			}	
		}
	}
}

I am pretty sure the main function is acting fine because if I just throw a getc() it will do what I want it to. I just do not see why the compare is not working appropriately. Any help would be greatly appreciated.
 

Re: RFID Project Help

You're not setting the terminating \0 for check[], don't know if variables are zerod with CCS as recommended by the C standard? If not, the compare would fail.

Otherwise, the read character string is different from "1100B8E8D1". If so, you can't really expect forum members to know why!
 

    Carnal

    Points: 2
    Helpful Answer Positive Rating
Re: RFID Project Help

Check the datasheet of the RFID reader you are using to determing the format of the data that the device returns. It is entirely possible the the null termination is giving you some headaches.

Cheers
Slayer
 

    Carnal

    Points: 2
    Helpful Answer Positive Rating
Re: RFID Project Help

You guys were right it was basically the null termination. It works fine now thanks a lot for your help!
 

Re: RFID Project Help

can u give me ur sample code for ur proj?

i am looking for a code that i could test using vb for rfid reader...pls send to jerries_27...tnx...take care!gudluck
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top