RFID Reader
Rvo11
Posts: 4
Right now My project partner and I are trying to create a program where if we bring a certain card up to the reader it will read the entire code and make a decision at the end of the byte and tell us what it is and what number we installed it to remember. At the moment we have created a program that can show the memorization of the cards for a certain number, but can't turn off the LED DIGIT counter. Can you come up with a program that can incoporate all of this?
Comments
More importantly, can YOU?
You'll need to describe what you want more thoroughly, post your code thus far, and identify what it's not doing for any useful help.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·"If you build it, they will come."
'
' File....... RFID.BS2
' Purpose.... RFID Tag Reader / Simple Security System
' Author..... (c) Parallax, Inc. -- All Rights Reserved
' E-mail..... support@parallax.com
' Started....
' Updated.... 09 SEPT. 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] 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.
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] 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
'
[noparse][[/noparse] 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 5
#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?
'
[noparse][[/noparse] 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
pinCounter VAR Nib
OUTH = %00000000
DIRH = %11111111
'
[noparse][[/noparse] EEPROM Data ]
Tag1 DATA "28001D66F5" ' valid tags
Tag2 DATA "3C0073E205"
Tag3 DATA "1700800E32"
Tag4 DATA "170081B810"
Tag5 DATA "24008CEADA"
Name0 DATA "Unauthorized", CR, 0
Name1 DATA "Tag 1 (50mm round)", CR, 0
Name2 DATA "Tag 2 (Key Fob)", CR, 0
Name3 DATA "Tag 3 (Credit Card 1)", CR, 0
Name4 DATA "Tag 4 (Credit Card 2)", CR, 0
Name5 DATA "Tag 5 (25mm round)", CR, 0
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Enable ' turn of RFID reader
LOW Latch ' lock the door!
'
[noparse][[/noparse] Program Code ]
Main:
LOW Enable ' activate the reader
#IF __No_SPRAM #THEN
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
#ELSE
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
#ENDIF
HIGH Enable ' deactivate reader
Check_List:
DO
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
IF (tagNum = 1) THEN
OUTH = %10000100
DEBUG "Welcome Raymond" '1
PAUSE 1000
ELSEIF (tagNum = 2) THEN
OUTH = %11010011
DEBUG "Go Away Sarafina!" '2
PAUSE 1000
ELSEIF (tagNum = 3) THEN
OUTH = %11010110
DEBUG "Nice Hair Josiah!" '3
PAUSE 1000
ELSEIF (tagnum = 4) THEN
OUTH = %10110100
DEBUG "Failure is NOT an Option!" '4
PAUSE 1000
ELSEIF (tagNum = 5) THEN
OUTH = %01110110
DEBUG "Hunter is the Winner!" '5
PAUSE 1000
ENDIF
NEXT
DIRH = %00000000
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
GOTO Main
LOOP
END
'
[noparse][[/noparse] Subroutines ]
' Prints name associated with RFID tag
Show_Name:
DEBUG DEC tagNum, ": "
LOOKUP tagNum,
[noparse][[/noparse]Name0, Name1, Name2, Name3, Name4, Name5], idx ' point to first character
DO
READ idx, char ' read character from name
IF (char = 0) THEN EXIT ' if 0, we're done
END
DEBUG char ' otherwise print it
idx = idx + 1 ' point to next character
LOOP
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
' =========================================================================
'
' File....... RFID.BS2
' Purpose.... RFID Tag Reader / Simple Security System
' Author..... (c) Parallax, Inc. -- All Rights Reserved
' E-mail..... support@parallax.com
' Started....
' Updated.... 09 SEPT. 2005
'
' {$STAMP BS2}
' {$PBASIC 2.5}
'
' =========================================================================
'
[noparse][[/noparse] 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.
'
[noparse][[/noparse] Revision History ]
'
[noparse][[/noparse] 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
'
[noparse][[/noparse] 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 5
#DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM?
'
[noparse][[/noparse] 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
pinCounter VAR Nib
OUTH = %00000000
DIRH = %11111111
'
[noparse][[/noparse] EEPROM Data ]
Tag1 DATA "28001D66F5" ' valid tags
Tag2 DATA "3C0073E205"
Tag3 DATA "1700800E32"
Tag4 DATA "170081B810"
Tag5 DATA "24008CEADA"
Name0 DATA "Unauthorized", CR, 0
Name1 DATA "Tag 1 (50mm round)", CR, 0
Name2 DATA "Tag 2 (Key Fob)", CR, 0
Name3 DATA "Tag 3 (Credit Card 1)", CR, 0
Name4 DATA "Tag 4 (Credit Card 2)", CR, 0
Name5 DATA "Tag 5 (25mm round)", CR, 0
'
[noparse][[/noparse] Initialization ]
Reset:
HIGH Enable ' turn of RFID reader
LOW Latch ' lock the door!
'
[noparse][[/noparse] Program Code ]
Main:
LOW Enable ' activate the reader
#IF __No_SPRAM #THEN
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), STR buf\10] ' wait for hdr + ID
#ELSE
SERIN RX, T2400, [noparse][[/noparse]WAIT($0A), SPSTR 10]
#ENDIF
Subroutine_Name:
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
IF (tagNum = 1) THEN
OUTH = %10000100
DEBUG "Welcome Raymond" '1
PAUSE 1000
END
ELSEIF (tagNum = 2) THEN
OUTH = %11010011
DEBUG "Go Away Sarafina!" '2
PAUSE 1000
GOSUB Subroutine_Name
RETURN
END
GOSUB Subroutine_Name
ELSEIF (tagNum = 3) THEN
OUTH = %11010110
DEBUG "Nice Hair Josiah!" '3
PAUSE 1000
END
ELSEIF (tagnum = 4) THEN
OUTH = %10110100
DEBUG "Failure is NOT an Option!" '4
PAUSE 1000
END
ELSEIF (tagNum = 5) THEN
OUTH = %01110110
DEBUG "Hunter is the Winner!" '5
PAUSE 1000
END
DIRH = %00000000
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
GOTO Main
END
'
[noparse][[/noparse] Subroutines ]
' Prints name associated with RFID tag
Show_Name:
DEBUG DEC tagNum, ": "
LOOKUP tagNum,
[noparse][[/noparse]Name0, Name1, Name2, Name3, Name4, Name5], idx ' point to first character
DO
READ idx, char ' read character from name
IF (char = 0) THEN EXIT ' if 0, we're done
END
DEBUG char ' otherwise print it
idx = idx + 1 ' point to next character
LOOP
RETURN
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 5/25/2010 12:15:46 AM GMT