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

Store Strings in Array for Comparison

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



Joined: 01 Nov 2009
Posts: 15

View user's profile Send private message

Store Strings in Array for Comparison
PostPosted: Mon Mar 29, 2010 11:27 pm     Reply with quote

Hi all,
I am working on an RFID reader module using a PIC16F688. I have the chip reading the serial data correctly and it can correctly identify a key. The only problem is that currently I have only one key stored. This is how I stored it:

Code:

char password[11];
strcpy(password,"112254DFF5");
password[10]='\0';


and this is how I compared (which works):
Code:

answer=strcmp(input,password);


How would I go about creating an array of passwords that I can compare with the "input" string. I want to be able to store a number of passwords, and I want the chip to cycle through each possibility before granting/denying access. I think I could come up with some sort of inefficient way to do this, however I was thinking maybe someone knew an easy way to do it!
Thanks!

DS.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 10:28 am     Reply with quote

You need to create a 2-dimensional array of strings, and then you
need to step through the array and compare it to your input string.
These threads contain sample code to do this:

From Ttelmah:
http://www.ccsinfo.com/forum/viewtopic.php?t=31144
From srhoar:
http://www.ccsinfo.com/forum/viewtopic.php?t=28159
ds



Joined: 01 Nov 2009
Posts: 15

View user's profile Send private message

PostPosted: Tue Mar 30, 2010 11:32 am     Reply with quote

Thanks for the quick reply! This helps. I will take a look at it and try something out!
Thanks again!

DS.
ds



Joined: 01 Nov 2009
Posts: 15

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 2:38 pm     Reply with quote

This works great! However, how do I make it so that I can add keys without reprogramming to chip? How can I expand the array within the program? Or is this something better suited with another method?
Thanks!

DS
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Mar 31, 2010 2:59 pm     Reply with quote

Put the new keys into Data EEprom (internal eeprom) inside the PIC.

Then when a password is entered by the user, read a key from data
eeprom into a RAM array. Compare it to the password. If it doesn't
match, then read the next key from data eeprom and compare it, and
so on.

You will need some way to know the number of keys that are stored
in data eeprom. You could allocate one byte in data eeprom to hold
the number of keys. Update that value whenever you add a new key.

I don't know if you intend to add new keys through a user interface,
(serial port ?) or if you intend to program data eeprom with an ICD.
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