How to compare strings/array? RFID Project


Closed Thread
Results 1 to 40 of 101

Hybrid View

  1. #1
    Join Date
    Jul 2003
    Location
    Colorado Springs
    Posts
    4,959


    Did you find this post helpful? Yes | No

    Default

    "Program/Verify Data" must be checked for it to write EEPROM data when programming.

    <img src="http://www.picbasic.co.uk/forum/attachment.php?attachmentid=1940&stc=1&d=118807518 2">
    <br>
    Attached Images Attached Images  
    DT

  2. #2
    Join Date
    Aug 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    I already have the "Program/Verify Data" option checked. Also if I Read the chip after Programming it, I do see the EEPROM data present in the Data EEPROM window. So it's definitely writing to the EEPROM. It's just not reading it for some reason.

    Also some other things I tried just now was switching to the internal 4MHz resonator and trying a second chip in case it was a bad chip. Neither made any difference.

  3. #3
    Join Date
    Aug 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Default

    Ok, get this! I just tried using a 16F84A instead of the 16F628A using nearly the exact same code and it works! I just removed the CMCON = 7 and DEFINE OSC 20 and stuck a 4MHz resonator on the board. With the 84A the LCD reads out the proper values one after the other, 10,2A,54,FF,7C. So now it looks like there is either something weird happening when I compile or the 628A does not like this code. Any ideas? I'd rather not have to step down my chip for this and have to order more old 16F84A's.

    Code:
    'CMCON = 7
    'DEFINE OSC 20
    
    char            VAR     Byte                    ' character from table
    loop var byte
    
    i con 254
    clrlcd con 1
    cgram con 64
    ddram con 128
    n96n con $4054
    pause 1000
    serout2 portb.7,n96n,[i,clrlcd]
    pause 1
    
    DATA @$00,$10,$2A,$54,$FF,$7C
    
    Main:
    for loop = 0 to 4
    READ loop, char        ' get tag data from table
    
    'Debug to LCD
    serout2 portb.7,n96n,[i,clrlcd]
    pause 500
    serout2 portb.7,n96n,[i,ddram+0]
    serout2 portb.7,n96n,[HEX char]
    pause 1000
    
    next
    end

  4. #4
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    Change this: READ (tagNum - 1 * 10 + idx), char ' get tag data from table

    to this: (((tagNum - 1) * 10) + idx), char ' get tag data from table

    Does it work now?
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  5. #5
    Join Date
    Aug 2007
    Posts
    7


    Did you find this post helpful? Yes | No

    Smile

    EUREKA!
    Thanks guys! You have been a huge help. I have finally figured it out.
    My problem was more like 3 problems...

    1. I have never done EEPROM stuff before so I was lost to begin with.
    2. As Bruce pointed out, the mathematical order of operations in one line was not correct. I guess the BS2 thinks a little differently from PBP in that respect.
    3. My PicBasic Pro compiler was Version 2.30 form 2000. It seems that v2.30 supports the PIC 16F628 but the PIC 16F628A was implemented in a later version. I have upgraded my PBP to version 2.47 and now the EEPROM features work correctly on the 16F628A. When I successfully tested a 16F84A using the same code, that lead me to question the compiler.

    So for future generations and the benefit of other people like me, here's my WORKING code that is tested successfully on a PIC 16F628A with a 20MHz resonator compiled using PBP v2.47. It reads data from the Parallax RFID Reader Module, compares it against known values stored in EEPROM and allows or denies access accordingly. Enjoy.

    Code:
    CMCON = 7   
    DEFINE OSC 20	'Set oscillator in MHz
    
    ' -----[ Variables ]-------------------------------------------------------
    
    buf	VAR	Byte(10)	' RFID bytes buffer
    tagNum	VAR	Byte	' from EEPROM table
    idx	VAR	Byte	' tag byte index
    char	VAR	Byte	' character from table
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Tag1	DATA	"100050A4B7"
    Tag2	DATA	"1000508E0A"
    Tag3	DATA	"10005091DC"
    Tag4	DATA	"100050203A"
    Tag5	DATA	"100050DA36"
    
    ' -----[ Initialization ]--------------------------------------------------
    
    HIGH portb.3	' turn off RFID reader
    LOW portb.6	' lock the door!
    Low portb.4	'Turn off LED
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
    
    LOW portb.3				' activate the reader
    SERIN2 portb.2, 396, [WAIT($0A), STR buf\10]	' wait for hdr + ID
    HIGH portb.3				' deactivate reader
    
    Check_List:
      FOR tagNum = 1 to 5			' scan through known tags
        FOR idx = 0 TO 9				' scan bytes in tag
        READ (((tagNum-1) * 10) + idx), char		' get tag data from table
        IF (char <> buf(idx)) THEN Bad_Char		' compare tag to table
        NEXT
        GOTO Tag_Found				' all bytes match!
    Bad_Char:					' try next tag
      NEXT
    
    Bad_Tag:
      tagNum = 0
      FREQOUT portb.5, 1000 */ $100, 115 */ $100	' groan
      PAUSE 1000
      GOTO Main
    
    Tag_Found:
      HIGH portb.6				' remove latch
      High portb.4				' Light LED
      FREQOUT portb.5, 2000 */ $100, 880 */$100	' beep
      LOW portb.6				' restore latch
      Low portb.4				' LED OFF
      GOTO Main

  6. #6
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    The BASIC Stamp solves math problems in the order they are written; from left to right. The
    result of each operation is fed into the next operation. So to compute -
    Code:
        12 + 3 * 2 / 5
    
    ...the BASIC Stamp goes through a sequence like this:
    
        12 + 3 = 15
        15 * 2 = 30
        30 / 5 = 6
    Unlike the BASIC Stamp, the PBP Compiler performs all math operations in full hierarchal
    order. This means that there is precedence to the operators.

    Multiplies and divides are performed before adds and subtracts, for example:
    Code:
        12 + 3 * 2 / 5
    
    ...PBP goes through a sequence like this:
    
        3 * 2 = 6    multiply first
        6 / 5 = 1.2  divide second (the .2 is lost)
        12 + 1 = 13  add last
    Forcing the addition first with parenthesis like: (12 + 3) * 2 / 5 would return the correct
    result. Good stuff to remember when porting BASIC Stamp code over to PBP.

    I haven't played with a BASIC Stamp in years, but once I looked in the Stamp editor help
    file under PBASIC Operators, it was obvious. I'm glad you got it working. Looks like a
    fun project.

    Maybe you could post your final version in the code examples section? Could save someone
    else using the Parallax RFID components with PBP a lot of head-scratching...;o}
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  7. #7
    Join Date
    Nov 2008
    Location
    Fort Collins, Colorado
    Posts
    8


    Did you find this post helpful? Yes | No

    Default RFID troubles

    I know I'm resurrecting a dead thread here but I've searched and can't quite find what i'm looking for. I'm using a Parallax RFID reader and a PIC 16F88, with a 4 line LCD. Right now I'm just trying to get the tag ID's to display on the LCD. So far I can get the RFID to turn on and read a tag, but the information sent to the display is cryptic. I would appreciate any help you might be able to give. Thanks!

    Here's the code I have so far.


    Code:
    'RFID and LCD test
    
    DEFINE OSC8
    OSCCON=%01110000
    
    ANSEL=0
    
    led		VAR PORTB.3	'led
    rx		VAR PORTB.0	'Serial input from RFID reader
    lcd		VAR PORTB.5	'Serial Output to LCD 
    rfid	VAR PORTB.1	'Enable rfid  low= on
    
    buf		VAR BYTE(10)	'Tag code stored as word
    
    Pause 1000
    
    High rfid
    
    High led
    Pause 1000
    Low led
    
    SEROUT lcd,0,[$FE,1]
    SEROUT lcd,0,[$FE,1,"Test"]
    
    Pause 4000
    
    High led
    Pause 3000
    Low led
    
    low rfid
    
    SERIN2 rx,396,[Wait($0A ),STR buf\10]
    
    High rfid
    
    High led
    Pause 2000
    Low led
    
    Pause 500
    SEROUT lcd,0,[$FE,1]
    SEROUT lcd,0,[$FE,1,"Tag number"]
    SEROUT lcd,0,[$FE,$C0,buf]
    Last edited by CSU_2010; - 20th November 2008 at 19:09.

  8. #8
    Join Date
    Oct 2010
    Posts
    413


    Did you find this post helpful? Yes | No

    Default Re: How to compare strings/array? RFID Project

    Quote Originally Posted by dan-tron View Post
    EUREKA!
    Thanks guys! You have been a huge help. I have finally figured it out.
    My problem was more like 3 problems...

    1. I have never done EEPROM stuff before so I was lost to begin with.
    2. As Bruce pointed out, the mathematical order of operations in one line was not correct. I guess the BS2 thinks a little differently from PBP in that respect.
    3. My PicBasic Pro compiler was Version 2.30 form 2000. It seems that v2.30 supports the PIC 16F628 but the PIC 16F628A was implemented in a later version. I have upgraded my PBP to version 2.47 and now the EEPROM features work correctly on the 16F628A. When I successfully tested a 16F84A using the same code, that lead me to question the compiler.

    So for future generations and the benefit of other people like me, here's my WORKING code that is tested successfully on a PIC 16F628A with a 20MHz resonator compiled using PBP v2.47. It reads data from the Parallax RFID Reader Module, compares it against known values stored in EEPROM and allows or denies access accordingly. Enjoy.

    Code:
    CMCON = 7   
    DEFINE OSC 20	'Set oscillator in MHz
    
    ' -----[ Variables ]-------------------------------------------------------
    
    buf	VAR	Byte(10)	' RFID bytes buffer
    tagNum	VAR	Byte	' from EEPROM table
    idx	VAR	Byte	' tag byte index
    char	VAR	Byte	' character from table
    
    ' -----[ EEPROM Data ]-----------------------------------------------------
    
    Tag1	DATA	"100050A4B7"
    Tag2	DATA	"1000508E0A"
    Tag3	DATA	"10005091DC"
    Tag4	DATA	"100050203A"
    Tag5	DATA	"100050DA36"
    
    ' -----[ Initialization ]--------------------------------------------------
    
    HIGH portb.3	' turn off RFID reader
    LOW portb.6	' lock the door!
    Low portb.4	'Turn off LED
    
    ' -----[ Program Code ]----------------------------------------------------
    
    Main:
    
    LOW portb.3				' activate the reader
    SERIN2 portb.2, 396, [WAIT($0A), STR buf\10]	' wait for hdr + ID
    HIGH portb.3				' deactivate reader
    
    Check_List:
      FOR tagNum = 1 to 5			' scan through known tags
        FOR idx = 0 TO 9				' scan bytes in tag
        READ (((tagNum-1) * 10) + idx), char		' get tag data from table
        IF (char <> buf(idx)) THEN Bad_Char		' compare tag to table
        NEXT
        GOTO Tag_Found				' all bytes match!
    Bad_Char:					' try next tag
      NEXT
    
    Bad_Tag:
      tagNum = 0
      FREQOUT portb.5, 1000 */ $100, 115 */ $100	' groan
      PAUSE 1000
      GOTO Main
    
    Tag_Found:
      HIGH portb.6				' remove latch
      High portb.4				' Light LED
      FREQOUT portb.5, 2000 */ $100, 880 */$100	' beep
      LOW portb.6				' restore latch
      Low portb.4				' LED OFF
      GOTO Main
    hello all,

    i would like to see the schematic of the above code if it is possible.

    One more thing that i would like to incude at the code is to identify the name of the target id.

    For example, once you pass the RFID chip from the reader, on the display to give you the name of the carrier.

    if i have a chip with a target id : 123456789012 then i would like once i pass it from the reader to give a name like ASTANAPANE.

    I guess that on the code i have to corespond the name to the target id.

    How can we do that.

    I have bought the modules from SPARKFUN and the RFID chips also from them.

    I would like to make a small project for my room.

    thanks for any suggestions.

    Best Regards
    Last edited by astanapane; - 28th March 2011 at 10:45.

  9. #9
    Join Date
    Nov 2006
    Location
    Murrieta, CA
    Posts
    62


    Did you find this post helpful? Yes | No

    Lightbulb Re: How to compare strings/array? RFID Project

    Check_List:
    FOR tagNum = 1 to 5 ' scan through known tags
    FOR idx = 0 TO 9 ' scan bytes in tag
    READ (((tagNum-1) * 10) + idx), char ' get tag data from table
    IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table
    NEXT
    GOTO Tag_Found ' all bytes match!
    Bad_Char: ' try next tag
    NEXT
    whenever the PIC identifies a tag stored in the EEPROM it still holds onto the "tagNum" variable. from there you can have your program branch off with the "tagNum" variable to display whatever you want. for argument sake lets say your third RFID badge is yours then:

    Code:
    Tag_Found:
    IF tagNum = 3 then displayName
    GOTO Main
    
    displayName:
    Serout2 portc.0,84,["ASTANAPANE"]    'assuming your display is on portc.0 @ 9600 baud
    pause 5000                                       'Pause 5 sec then clear display
    gosub CLRLCD
    Goto main
    Hope this helps... Cheers

Similar Threads

  1. Parallax RFID Reader code example
    By dan-tron in forum Code Examples
    Replies: 4
    Last Post: - 19th April 2013, 22:16
  2. A Temperature & Humidity Data Recorder Project
    By Oldspring in forum Off Topic
    Replies: 0
    Last Post: - 9th July 2008, 18:47
  3. Replies: 3
    Last Post: - 12th March 2008, 05:33
  4. Free Web based RFID Online Courses
    By Thirumoorthy in forum General
    Replies: 0
    Last Post: - 19th November 2007, 13:38
  5. Free web based RFID online Course
    By Lesikar in forum GPS
    Replies: 0
    Last Post: - 19th October 2007, 22:28

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts