|
|
View previous topic :: View next topic |
Author |
Message |
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Mon Apr 09, 2012 10:58 am |
|
|
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
|
|
Posted: Mon Apr 09, 2012 11:23 am |
|
|
as PCM wisely counsels ,
you seem to be ONE
short of being where you want to be |
|
|
yasotha
Joined: 05 Mar 2012 Posts: 6
|
HI |
Posted: Wed Apr 11, 2012 10:42 am |
|
|
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
|
|
Posted: Wed Apr 11, 2012 11:21 am |
|
|
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
|
hi.. |
Posted: Sat May 12, 2012 8:45 am |
|
|
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
|
|
Posted: Sat May 12, 2012 4:58 pm |
|
|
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
|
|
Posted: Sat May 12, 2012 5:06 pm |
|
|
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 |
|
|
|
|
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
|