rfid reader code question
mikea
Posts: 283
I downloaded this code from the parallax website for product downloads. I bought rfid tags and substituted the 10 digit tag i.d. into the eeprom data table (as tag #3 in the code below). I think im missing something because it shows up in the debug terminal as unauthorized, and wont activate pin 3 (the intended door unlock).Any help would be appreciated......I just found another program that solved my first problem. It read the tag and displayed the i.d. which ended up being different from the i.d. stamped on the front of the tag. I substituted the "read i.d." and this program worked. Why is the printed id different from the read id? -mike
' ========================================================================= ' ' File....... RFID.BS2 ' Purpose.... RFID Tag Reader / Simple Security System ' Author..... (c) Parallax, Inc. -- All Rights Reserved ' E-mail..... [EMAIL="support@parallax.com"]support@parallax.com[/EMAIL] ' Started.... ' Updated.... 09 SEPT. 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[ Program Description ]--------------------------------------------- ' ' Reads tags from a Parallax RFID reader and compares to known tags (stored ' in EEPROM table). If tag is found, the program will disable a lock. ' -----[ Revision History ]------------------------------------------------ ' -----[ I/O Definitions ]------------------------------------------------- Enable PIN 0 ' low = reader on RX PIN 1 ' serial from reader Spkr PIN 2 ' speaker output Latch PIN 3 ' lock/latch control ' -----[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E, BS2PE T1200 CON 813 T2400 CON 396 T4800 CON 188 T9600 CON 84 T19K2 CON 32 TMidi CON 12 T38K4 CON 6 #CASE BS2SX, BS2P T1200 CON 2063 T2400 CON 1021 T4800 CON 500 T9600 CON 240 T19K2 CON 110 TMidi CON 60 T38K4 CON 45 #CASE BS2PX T1200 CON 3313 T2400 CON 1646 T4800 CON 813 T9600 CON 396 T19K2 CON 188 TMidi CON 108 T38K4 CON 84 #ENDSELECT SevenBit CON $2000 Inverted CON $4000 Open CON $8000 Baud CON T2400 #SELECT $STAMP #CASE BS2, BS2E TmAdj CON $100 ' x 1.0 (time adjust) FrAdj CON $100 ' x 1.0 (freq adjust) #CASE BS2SX TmAdj CON $280 ' x 2.5 FrAdj CON $066 ' x 0.4 #CASE BS2P TmAdj CON $3C5 ' x 3.77 FrAdj CON $044 ' x 0.265 #CASE BS2PE TmAdj CON $100 ' x 1.0 FrAdj CON $0AA ' x 0.665 #CASE BS2PX TmAdj CON $607 ' x 6.03 FrAdj CON $2A ' x 0.166 #ENDSELECT LastTag CON 3 #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM? ' -----[ Variables ]------------------------------------------------------- #IF __No_SPRAM #THEN buf VAR Byte(10) ' RFID bytes buffer #ELSE chkChar VAR Byte ' character to test #ENDIF tagNum VAR Nib ' from EEPROM table idx VAR Byte ' tag byte index char VAR Byte ' character from table ' -----[ EEPROM Data ]----------------------------------------------------- ' valid tags Tag1 DATA "04129C1A1C" Tag2 DATA "041402CCD7" Tag3 DATA "0030781520" Name0 DATA "Unauthorized", CR, 0 Name1 DATA "Tag 1 (White Card)", CR, 0 Name2 DATA "Tag 2 (Oval)", CR, 0 Name3 DATA "Tag 3 (Small Round)", CR, 0 ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH Enable ' turn of RFID reader LOW Latch ' lock the door! ' -----[ Program Code ]---------------------------------------------------- Main: LOW Enable ' activate the reader #IF __No_SPRAM #THEN SERIN RX, T2400, [WAIT($0A), STR buf\10] ' wait for hdr + ID #ELSE SERIN RX, T2400, [WAIT($0A), SPSTR 10] #ENDIF HIGH Enable ' deactivate reader Check_List: FOR tagNum = 1 TO LastTag ' 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 __No_SPRAM #THEN IF (char <> buf(idx)) THEN Bad_Char ' compare tag to table #ELSE GET idx, chkChar ' read char from SPRAM IF (char <> chkChar) THEN Bad_Char ' compare to table #ENDIF NEXT GOTO Tag_Found ' all bytes match! Bad_Char: ' try next tag NEXT Bad_Tag: tagNum = 0 GOSUB Show_Name ' print message FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj ' groan PAUSE 1000 GOTO Main Tag_Found: GOSUB Show_Name ' print name HIGH Latch ' remove latch FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj ' beep LOW Latch ' restore latch GOTO Main END ' -----[ Subroutines ]----------------------------------------------------- ' Prints name associated with RFID tag Show_Name: DEBUG DEC tagNum, ": " LOOKUP tagNum, [Name0, Name1, Name2, Name3], idx ' point to first character DO READ idx, char ' read character from name IF (char = 0) THEN EXIT ' if 0, we're done DEBUG char ' otherwise print it idx = idx + 1 ' point to next character LOOP RETURN
Comments