CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

RFID coding

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
yasotha



Joined: 05 Mar 2012
Posts: 6

View user's profile Send private message

RFID coding
PostPosted: Mon Apr 09, 2012 2:20 am     Reply with quote

Good day everyone,

Here I've attached the coding I've done for RFID (read & display tags ID on LCD). I'm able to read all the tags id but then when I altered the coding where few tags should be displayed as 'user not found'. I'm not able to get the output. I'm not sure what went wrong in the coding...anyone please kindly help me.
Code:

#include <18F4525.h>
#include <string.h>

/*configuration*/
#FUSES NOWDT         //No Watch Dog Timer
#FUSES HS            //Crystal Osc (<= 4mhz)
#FUSES PUT            //Power Up Timer
#FUSES NOPROTECT      //Code not protected from reading
#FUSES NODEBUG         //No Debug mode for ICD
#FUSES NOBROWNOUT      //Don't Reset when brownout detected
#FUSES NOLVP   //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD         //No EE protection
#FUSES NOWRT         //Program memory not write protected

#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,PARITY=N) //RFID io

#define   button1  RB0   //button (active low)
#define   led1     RA0   //led 1 (active high)

#include <flex_lcd.c>

void main()
{
 char i,j;
 char code[12];
 char passa[12] = {"0010268629"};
 char passb[12] = {"0008006531"};
   
 setup_adc_ports(NO_ANALOGS);
 setup_adc(ADC_OFF);
 setup_spi(SPI_SS_DISABLED);
 setup_timer_0(RTCC_INTERNAL);
 setup_timer_1(T1_DISABLED);
 setup_timer_2(T2_DISABLED,0,1);

 set_tris_a(0x00);
 set_tris_d(0x00);
 set_tris_c(0xA0);
 
 lcd_init();

 while (TRUE){
   lcd_putc("\f ");
   lcd_gotoxy(5,1);
   printf(lcd_putc, " RFID ");
   lcd_gotoxy(4,2);
   printf(lcd_putc, " TESTING ");
   delay_ms(2000);
   printf(lcd_putc,"\f");
   printf(lcd_putc, " PlEASE TOUCH ");
   printf(lcd_putc,"\n");
   printf(lcd_putc, " YOUR ID CARD ");
 
   for(j=0;j<11;j++)
     code[j]=i=fgetc();

   printf(lcd_putc,"\f");
   printf(lcd_putc, "user ID:\n ");
   printf(lcd_putc,code);
   output_high(PIN_A0);
   delay_ms(2000);
   output_low(PIN_A0);

    if(strcmp(code,passa))
    {
      output_high(PIN_A0);
      printf(lcd_putc,"\f user name:\n Yasotha ");
      printf(code);
      delay_ms(1000);
      output_low(PIN_A0);
      lcd_putc("\f ");
      delay_ms(1000);
    }
    else if (strcmp(code,passb))
    {
      output_high(PIN_A0);
      printf(lcd_putc,"\f user name:\n Padmanathan");
      printf(code);
      delay_ms(1000);
      output_low(PIN_A0);
      lcd_putc("\f ");
    }
    else
    {
      output_low(PIN_A0);
      printf(lcd_putc,"\f user name:\n not found");
      printf(code);
      lcd_putc("\f ");
    }

 }

}
temtronic



Joined: 01 Jul 2010
Posts: 9225
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Mon Apr 09, 2012 7:12 am     Reply with quote

1) always add 'errors' to the USE RS232(....) directive when using the hardware UART.

2) go back to your working code and then make 1 change. See what happens.

3)this...

code[j]=i=fgetc();


...doesn't 'look right' to me.....
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Apr 09, 2012 10:58 am     Reply with quote

Quote:
if(strcmp(code,passa))
{

Look up strcmp() in a C manual. What is the return value if the strings
match ? What return value are you checking for in your code ?
When you answer these questions you will solve the problem.
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Apr 09, 2012 11:23 am     Reply with quote

as PCM wisely counsels ,
you seem to be ONE
Quote:

!

short of being where you want to be
yasotha



Joined: 05 Mar 2012
Posts: 6

View user's profile Send private message

HI
PostPosted: Wed Apr 11, 2012 10:42 am     Reply with quote

Hi, I don't really get the meaning. I have searched in c manual but I really don't understand.
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Wed Apr 11, 2012 11:21 am     Reply with quote

Tell us what the various output results for the strcmp function are. Type them out in a post. Then look at your IF statement with strcmp in it and try to figure out what the result will be.
yasotha



Joined: 05 Mar 2012
Posts: 6

View user's profile Send private message

hi..
PostPosted: Sat May 12, 2012 8:45 am     Reply with quote

Code:
#include <18F4525.h>
#include <string.h>

/*configuration*/
#FUSES NOWDT         //No Watch Dog Timer
#FUSES HS            //Crystal Osc (<= 4mhz)
#FUSES PUT            //Power Up Timer
#FUSES NOPROTECT      //Code not protected from reading
#FUSES NODEBUG         //No Debug mode for ICD
#FUSES NOBROWNOUT      //Don't Reset when brownout detected
#FUSES NOLVP   //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOCPD         //No EE protection
#FUSES NOWRT         //Program memory not write protected


#use delay(clock=20000000)
#use rs232(baud=9600,xmit=PIN_C6,rcv=PIN_C7,bits=8,PARITY=N,ERRORS) //RFID io


#include <flex_lcd.c>

void main()
{
   char i,j;
   char code[11];
   char passa[11] = {"0004870730"};
   char passb[11] = {"0004877973"};

   
   setup_adc_ports(NO_ANALOGS);
   setup_adc(ADC_OFF);
   setup_spi(SPI_SS_DISABLED);
   setup_timer_0(RTCC_INTERNAL);
   setup_timer_1(T1_DISABLED);
   setup_timer_2(T2_DISABLED,0,1);

   set_tris_a(0x00);
   set_tris_b(0x00);
   set_tris_c(0xA0);
 
   lcd_init();


   while (TRUE){
   printf(lcd_putc, " RFID Wireless ");
   printf(lcd_putc,"\n");
   printf(lcd_putc, "  Door System  ");
   delay_ms(2000);
   printf(lcd_putc,"\f");
   printf(lcd_putc, " Place your ID ");
   printf(lcd_putc,"\n");
   printf(lcd_putc, " on the reader");
   
   for(j=0;j<10;j++)
   code[j]=i=fgetc();
   printf(lcd_putc,"\f");
   printf(lcd_putc, "user ID:\n");
   printf(lcd_putc,code);
   delay_ms(2000);
   printf(lcd_putc,"\f");
   
 if(!strcmp(code,passa))
    {

      printf(lcd_putc,"\f user name:\n yasotha");
      delay_ms(500);
    }

    else if (!strcmp(code,passb))
    {
      printf(lcd_putc,"\f user name:\n Padmanathan");
      delay_ms(500);
    }
    else
    {
      printf(lcd_putc,"\f user name:\n not found");
      delay_ms(1000);
    }
   
   }
   }
 


i still cant find solution to compare two ID's. It displays all the ID's on LCD. any solutions?

strcmp if both value matches it gives 0.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sat May 12, 2012 4:58 pm     Reply with quote

You need to develop an attitude of "I will find the problem !", and then
learn to put in diagnostic code to help you see what the program is doing.

For example, you have two arrays. One has a password in it already.
The other array has a password that is typed in by the user. For some
reason, your strcmp() doesn't give the expected result. So, what to do ?

Answer: Put in diagnostic code to display the contents of both arrays
in hex, and also display the result from strcmp(). Then you can see
what is happening:
Code:

 for(j=0;j<10;j++)
   code[j]=i=fgetc();
   printf(lcd_putc,"\f");
   printf(lcd_putc, "user ID:\n");
   printf(lcd_putc,code);
   delay_ms(2000);
   printf(lcd_putc,"\f");

// ====== Diagnostic code ==========
printf("\n\r");

printf("code[]=  ");
for(i=0; i<11; i++)
     printf("%x ", code[i]);
printf("\n\r");

printf("passa[]= ");
for(i=0; i<11; i++)
     printf("%x ", passa[i]);
printf("\n\r");

i = strcmp(code, passa);
printf("strcmp result = %d \n\r", i);

// ===========================
   
 if(!strcmp(code,passa))
    {

      printf(lcd_putc,"\f user name:\n yasotha");
      delay_ms(500);
    }
 

Look for common problems such as missing the "0x00" byte on the end
of a string. Without that byte, it's not a string.


Also, get rid of this type of coding shown below. It's not normally done.
It's considered to be "messy", and it's not good for program maintenance
in the future. (Don't set two variables in the same line):
Quote:

code[j]=i=fgetc();
Mike Walne



Joined: 19 Feb 2004
Posts: 1785
Location: Boston Spa UK

View user's profile Send private message

PostPosted: Sat May 12, 2012 5:06 pm     Reply with quote

Work on the KISS principle.

You're having a problem with strcmp().

So, get rid of everything else and just work on that one piece of code.

Mike
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group