RFID Reader
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
' ======================================================================= ' ' File....... Soldering Station Time Controller.bs2 ' Purpose... To use RFID Card Reader and DS1302 ' Author.... Sam ' Started.... ' Updated.... 6-01-06 ' ' I Want to Thank Chris Savage, Jon Williams ,Tracy Allen and PJ Allen ' For Helping understand how To write these Card routines and the Time Routine ' -----[noparse][[/noparse] Program Description ]--------------------------------------------- ' ' To use RFID Card Reader and DS1302 With a BS2 ' ' To use differnet Card for differnet amount of Time ' ' EXAMPLES ' ' Card # 1 is fot 15 Minutes and 00 Seconds ' Card # 2 is fot 30 Minutes and 00 Seconds ' Card # 3 is fot 59 Minutes and 59 Seconds ' Card # 4 is fot 01 Hour and 59 Minutes and 59 Seconds....... Coming Soon...... ' ' ========================================================================= ' ' File....... RFID.BS2 ' Purpose.... RFID Tag Reader ' Author..... (c) Parallax, Inc. -- All Rights Reserved ' E-mail..... [url=mailto:support@parallax.com]support@parallax.com[/url] ' Started.... ' Updated.... 09 SEPT. 2005 ' ========================================================================= ' ' File...... DS1302_Demo.bs2 ' Purpose... Demonstrate The DS1302 Clock ' Author.... Chris Savage -- Parallax, Inc. ' E-mail.... [url=mailto:csavage@parallax.com]csavage@parallax.com[/url] ' Started... ' Updated... 10-09-2005 ' ' ' ======================================================================= ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- DataIO PIN 1 ' DS1302.6 Clock PIN 0 ' DS1302.7 CS1302 PIN 2 ' DS1302.5 Enable PIN 8 ' low = reader on RX PIN 7 ' serial from reader 'Not Used ' speaker output Relay PIN 10 ' control relay Invaild_Card PIN 15 ' Invaild_Card Led card15 PIN 14 ' 15 Min Card card30 PIN 13 ' 30 Min Card card60 PIN 12 ' 60 Min Card tick PIN 11 ' program running ' -----[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 #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) #ENDSELECT LastTag CON 3 #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM? WrSecs CON $80 ' Write Seconds RdSecs CON $81 ' Read Seconds WrMins CON $82 ' Write Minutes RdMins CON $83 ' Read Minutes WrHrs CON $84 ' Write Hours RdHrs CON $85 ' Read Hours CWPr CON $8E ' Write Protect Register WPr1 CON $80 ' Set Write Protect WPr0 CON $00 ' Clear Write Protect WrBurst CON $BE ' Write Burst Of Data RdBurst CON $BF ' Read Burst Of Data WrRam CON $C0 ' Write RAM Data RdRam CON $C1 ' Read RAM Data Hr24 CON 0 ' 24 Hour Mode Hr12 CON 1 ' 12 Hour Mode ' -----[noparse][[/noparse] Variables ]------------------------------------------------------- index VAR Byte ' Loop Counter reg VAR Byte ' Read/Write Address ioByte VAR Byte ' Data To/From DS1302 secs VAR Byte ' Seconds secs01 VAR secs.LOWNIB secs10 VAR secs.HIGHNIB mins VAR Byte ' Minutes mins01 VAR mins.LOWNIB mins10 VAR mins.HIGHNIB hrs VAR Byte ' Hours hrs01 VAR hrs.LOWNIB hrs10 VAR hrs.HIGHNIB date VAR Byte month VAR Byte day VAR Nib ' Day year VAR Byte ' Year ampm VAR hrs.BIT5 ' AM/PM Flag Bit clockMode VAR hrs.BIT7 ' 12/24 Hour Mode Bit ampmFlag VAR Bit ' 0 = AM, 1 = PM modeFlag VAR Bit ' 0 = 24, 1 = 12 (Hours) work VAR Byte ' Work Data #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 ' -----[noparse][[/noparse] EEPROM Data ]----------------------------------------------------- Tag1 DATA "04158DD890" ' valid tags Tag2 DATA "04158DCE28" Tag3 DATA "04158DCA62" Name0 DATA "........STOP.........", CR, 0 Name1 DATA "Tag 1 (15 MIN CARD)", CR, 0 Name2 DATA "Tag 2 (30 MIN CARD)", CR, 0 Name3 DATA "Tag 3 (1 HOUR CARD)", CR, 0 ' -----[noparse][[/noparse] Initialization ]-------------------------------------------------- Reset: HIGH Enable ' turn of RFID reader LOW relay ' lock the door! Init: reg = CWPr ' Initialize DS1302 ioByte = WPr0 ' Clear Write Protect GOSUB RTC_Out ' Send Command ' -----[noparse][[/noparse] Program Code ]---------------------------------------------------- Main: DEBUG CLS, CLS 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: 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 GOTO Routine0 Tag_Found: ON tagNum GOSUB Routine0, Routine1, Routine2, Routine3 ' -----[noparse][[/noparse] Subroutines ]----------------------------------------------------- ' Prints name associated with RFID tag Show_Name: DEBUG DEC tagNum, ": ", CR LOOKUP tagNum, [noparse][[/noparse]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 RTC_Out: HIGH CS1302 ' Select DS1302 SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg, ioByte] LOW CS1302 ' Deselect DS1302 RETURN RTC_In: HIGH CS1302 ' Select DS1302 SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]reg] SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]ioByte] LOW CS1302 ' Deselect DS1302 RETURN Set_Time: ' DS1302 Burst Write HIGH CS1302 ' Select DS1302 SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]WrBurst] SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]secs, mins, hrs, date, month, day, year, 0] LOW CS1302 ' Deselect DS1302 RETURN Get_Time: ' DS1302 Burst Read HIGH CS1302 ' Select DS1302 SHIFTOUT DataIO, Clock, LSBFIRST, [noparse][[/noparse]RdBurst] SHIFTIN DataIO, Clock, LSBPRE, [noparse][[/noparse]secs, mins, hrs, date, month, day, year] LOW CS1302 ' Deselect DS1302 RETURN ' -----[noparse][[/noparse]Card's Subroutines ]----------------------------------------------------- ' To use differnet Card for differnet amount of Time ' Card # 0 is fot Unauthorized CARD ' Card # 1 is fot 15 Minutes and 00 Seconds ' Card # 2 is fot 30 Minutes and 00 Seconds ' Card # 3 is fot 59 Minutes and 59 Seconds ' 'Unauthorized CARD Routine 'Unauthorized CARD Led Light...... Routine0: mins=$00 secs=$00 GOSUB Set_Time HIGH Invaild_Card 'Turn ON Led DO HIGH tick PAUSE 500 LOW tick GOSUB Get_Time IF mins=$00 AND secs=$20 THEN EXIT DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR DEBUG CR, CR, "Unauthorized CARD", CR LOOP DEBUG CLS, CLS ' Turn OFF Led LOW Invaild_Card GOTO main '15 Minutes CARD Routine Routine1: mins=$00 secs=$00 GOSUB Set_Time GOSUB Get_Time DO HIGH tick PAUSE 30 LOW tick IF mins=$00 AND secs=$05 THEN HIGH relay HIGH card15 ENDIF ' Turn ON Relay IF mins=$15 AND secs=$00 THEN EXIT GOSUB Get_Time DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR DEBUG CR, CR, "15 MIN CARD ", CR LOOP DEBUG CLS, CLS LOW relay LOW card15 ' Turn OFF Relay GOTO main '30 Minutes CARD Routine Routine2: mins=$00 secs=$00 GOSUB Set_Time GOSUB Get_Time DO HIGH tick PAUSE 30 LOW tick IF mins=$00 AND secs=$05 THEN HIGH relay HIGH card30 ENDIF ' Turn ON Relay IF mins=$30 AND secs=$00 THEN EXIT GOSUB Get_Time DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR DEBUG CR, CR, "30 MIN CARD " LOOP DEBUG CLS, CLS LOW relay LOW card30 ' Turn OFF Relay GOTO main '60 Minutes CARD Routine Routine3: mins=$00 secs=$00 GOSUB Set_Time GOSUB Get_Time DO HIGH tick PAUSE 30 LOW tick IF mins=$00 AND secs=$05 THEN ' Turn ON Relay HIGH relay HIGH card60 ENDIF IF mins=$59 AND secs=$59 THEN EXIT GOSUB Get_Time ' 60 MIN CARD DEBUG HOME, HEX2 mins, ":", HEX2 secs, CR DEBUG CR, CR, "60 MIN CARD " LOOP DEBUG CLS, CLS LOW relay LOW card60 ' Turn OFF Relay GOTO main▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any·
·
·
·
·
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
' ======================================================================= ' ' File....... ' Purpose... To use RFID Card Reader and different Routine ' Author.... Sam ' Started.... ' Updated.... 6-01-06 ' ' I Want to Thank Chris Savage, Jon Williams ,Tracy Allen and PJ Allen ' For Helping understand how To write these Card routines and the Time Routine ' -----[noparse][[/noparse] Program Description ]--------------------------------------------- ' ' To use RFID Card Reader and DS1302 With a BS2 ' ' To use differnet Card for----->> ' ' EXAMPLES ' Routine0: DEBUG " Card Not Found " ' Routine1: DEBUG "Welcome Raymond" '1 ' Routine2: DEBUG "Go Away Sarafina!" '2 ' Routine3: DEBUG "Nice Hair Josiah!" '3 ' Routine4: DEBUG "Failure is NOT an Option!" '4 ' Routine5: DEBUG "Hunter is the Winner!" '5 ' ' ========================================================================= ' ' File....... RFID.BS2 ' Purpose.... RFID Tag Reader ' Author..... (c) Parallax, Inc. -- All Rights Reserved ' E-mail..... [url=mailto:support@parallax.com]support@parallax.com[/url] ' Started.... ' Updated.... 09 SEPT. 2005 ' ' ======================================================================= ' {$STAMP BS2} ' {$PBASIC 2.5} ' -----[noparse][[/noparse] I/O Definitions ]------------------------------------------------- Enable PIN 0 ' low = reader on RX PIN 1 ' serial from reader ' -----[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 #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) #ENDSELECT LastTag CON 5 #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM? work VAR Byte ' Work Data #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 ' -----[noparse][[/noparse] EEPROM Data ]----------------------------------------------------- Tag1 DATA "04158DD890" ' valid tags # Tag2 DATA "04158DCE28" Tag3 DATA "04158DCA62" Tag4 DATA "0000000000" ' your card # Name0 DATA " Card Not Found " Name1 DATA " Welcome Raymond ", CR, 0 Name2 DATA " Go Away Sarafina! ", CR, 0 Name3 DATA " Nice Hair Josiah! " , CR, 0 Name4 DATA " Failure is NOT an Option!" , CR, 0 Name5 DATA " Hunter is the Winner! " , CR, 0 ' -----[noparse][[/noparse] Initialization ]-------------------------------------------------- Reset: HIGH Enable ' turn of RFID reader OUTH = %00000000 DIRH = %11111111 ' -----[noparse][[/noparse] Program Code ]---------------------------------------------------- Main: DEBUG CLS, CLS 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: 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 GOTO Routine0 Tag_Found: ON tagNum GOSUB Routine0, Routine1, Routine2, Routine3, Routine4, Routine5 ' -----[noparse][[/noparse] Subroutines ]----------------------------------------------------- ' Prints name associated with RFID tag Show_Name: DEBUG DEC tagNum, ": ", CR 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 DEBUG char ' otherwise print it idx = idx + 1 ' point to next character LOOP RETURN ' -----[noparse][[/noparse]Card's Subroutines ]----------------------------------------------------- Routine0: PAUSE 500 ' Your code for " Card Not Found " RETURN Routine1: OUTH = %10000100 '"Welcome Raymond" '1 PAUSE 1000 RETURN Routine2: OUTH = %11010011 ' "Go Away Sarafina!" '2 PAUSE 1000 RETURN Routine3: OUTH = %11010110 ' "Nice Hair Josiah!" '3 PAUSE 1000 RETURN Routine4: OUTH = %10110100 ' "Failure is NOT an Option!" '4 PAUSE 1000 RETURN Routine5: OUTH = %01110110 ' "Hunter is the Winner!" '5 PAUSE 1000 RETURN▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
·Now wanting to learn Spin· Thanks for any·
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 5/25/2010 12:15:46 AM GMT