Need help with RFID Card Reader Code
Eschatt
Posts: 16
I am relatively new to Basic Stamps. I am trying to use my Basic Stamp 2 to read the ID number of an RFID tag that I want to use for a RFID Lock Project. But when I try to run the RFID Card Reader Code from Parallex it comes up with the error messages including "Expected ":" or end-of-line". Any help getting the code to work would be much appreciated! Thanks!
Comments
Here are the two code that should try they are below
This code will tell you what your card # are RFID_basic.BS2
When you have your card # then use the RFID1.BS2
Where you see DATA " " This where you put your Card #
····························· ·· "Your Card # "
Where you see·DATA " " This where you put your Card Names at
···························· "Tag 3 (Small Round)"
Where you see LasTtag CON· "# " put the # of the· that you are using
························· LastTag········ CON···· "3"····
Where you see LOOKUP tagNum, you need to add Name"#" of the Last Card that you are using
···································· Name"3"
LastTag········ CON···· 3····
Tag1··········· DATA··· "0101A625F5"··········· ' valid tags
Tag2··········· DATA··· "04129C1A1C"
Tag3··········· DATA··· "041402CCD7"
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
LOOKUP tagNum,
········ [noparse][[/noparse]Name0, Name1, Name2, Name3], idx····· ' point to first character
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
··Thanks for any··that you may have and all of your time finding them
·
·
·
·
Sam
Post Edited (sam_sam_sam) : 5/2/2008 11:45:23 AM GMT
' {$STAMP BS2}
' =========================================================================
'
' File...... RFID_Demo.SXB
' Purpose... RFID tag reader / ID system
' Author.... Jon Williams, Parallax Inc.
' E-mail.... jwilliams@parallax.com
' Started...
' Updated... 01 MAR 2005
'
' =========================================================================
'
' Program Description
'
'
' Reads a passive tag with the Parallax RFID Reader, then displays the
' tag serial number and a name associated in a data table. This program
' sends its output to the Parallax Serial LCD module.
'
' Note: Program requires SX/B version 1.2 or later
'
' Device Settings
'
DEVICE SX28, OSCXT2, TURBO, STACKX, OPTIONX
FREQ 4_000_000
'
' IO Pins
'
Enable VAR RA.0 ' low to activeate RFID reader
RFID VAR RA.1 ' serial data from RFID
LCD VAR RA.2 ' serial out to Parallax Serial LCD
'
' Constants
'
RfidBaud CON "T2400" ' baud for RFID reader
LcdBaud CON "T9600" ' baud for serial LCD
LcdBkSpc CON $08 ' move cursor left
LcdRt CON $09 ' move cursor right
LcdLF CON $0A ' move cursor down 1 line
LcdCls CON $0C ' clear LCD (use PAUSE 5 after)
LcdCR CON $0D ' move pos 0 of next line
LcdBLon CON $11 ' backlight on
LcdBLoff CON $12 ' backlight off
LcdOff CON $15 ' LCD off
LcdOn1 CON $16 ' LCD on; cursor off, blink off
LcdOn2 CON $17 ' LCD on; cursor off, blink on
LcdOn3 CON $18 ' LCD on; cursor on, blink off
LcdOn4 CON $19 ' LCD on; cursor on, blink on
LcdLine1 CON $80 ' move to line 1, column 0
LcdLine2 CON $94 ' move to line 2, column 0
LastTag CON 3 ' 3 valid tags
'
' Variables
'
char VAR Byte
idx VAR Byte
serNum VAR Byte(10) ' serial number string
buf VAR Byte(10) ' for comparison with known tag
tagNum VAR Byte ' tag number
offset VAR Byte ' data table offset
pCount VAR Byte ' parameters count
regAddr VAR Byte ' register address
temp1 VAR Byte ' work vars
temp2 VAR Byte
' =========================================================================
PROGRAM Start
' =========================================================================
Pgm_Data: ' start of data tables
B1:
DATA "PARALLAX RFID ", 0 ' banner, line 1
B2:
DATA "Present ID Tag ", 0 ' banner, line 2
T0:
DATA "0000000000" ' placeholder
T1:
DATA "0F0184F20B" ' valid tags
T2:
DATA "0F01D9D263"
T3:
DATA "04129C1B43"
N0:
DATA "Unauthorized ", 0 ' name associated with tag
N1:
DATA "George W. Bush ", 0
N2:
DATA "Dick Cheney ", 0
N3:
DATA "Condoleeza Rice ", 0
' Memory offsets from start of data
Banner1 CON B1 - Pgm_Data
Banner2 CON B2 - Pgm_Data
Tag0 CON T0 - Pgm_Data
Tag1 CON T1 - Pgm_Data
Tag2 CON T2 - Pgm_Data
Tag3 CON T3 - Pgm_Data
Name0 CON N0 - Pgm_Data
Name1 CON N1 - Pgm_Data
Name2 CON N2 - Pgm_Data
Name3 CON N3 - Pgm_Data
'
' Subroutine Declarations
'
Wait_MS SUB 1, 2 ' pause x {, * y}
Print_Str SUB 1 ' print string to LCD
TX_Byte SUB 1 ' tx byte to LCD
RX_Byte SUB 1 ' rx byte from RFID
Get_RFID SUB ' get RFID string
Check_Tag SUB 1 ' compare tag to table entry
'
' Program Code
'
Start:
PLP_A = %0111 ' pull-up unused pins
PLP_B = %00000000
PLP_C = %00000000
HIGH Enable ' deactivate reader
Wait_MS 100 ' let LCD initialize
TX_Byte LcdOn1 ' no cursor
TX_Byte LcdCls
Wait_MS 5
Show_Banner:
TX_Byte LcdLine1
Print_Str Banner1
TX_Byte LcdLine2
Print_Str Banner2
Get_Tag:
Get_RFID ' get serial number from reader
TX_Byte LcdCls ' clear the LCD
Wait_MS 5
FOR idx = 0 TO 9 ' display the tag string
char = serNum(idx)
TX_Byte char
NEXT
Search_Tags: ' search db for tag
FOR idx = 1 TO LastTag
tagNum = idx
LOOKUP tagNum, Tag0, Tag1, Tag2, Tag3, offset
Check_Tag offset
IF tagNum > 0 THEN Show_Name ' if valid, show name
NEXT
Show_Name:
LOOKUP tagNum, Name0, Name1, Name2, Name3, offset
TX_Byte LcdLine2
Print_Str offset
Wait_MS 250, 12 ' wait 3 seconds
GOTO Show_Banner ' back to top
END
'
' Subroutines
'
' Use: Wait_MS mSecs {, multiplier}
' -- pauses for 'mSecs' { x multiplier }
Wait_MS:
pCount = __PARAMCNT ' parameters
temp1 = __PARAM1 ' char to send
temp2 = __PARAM2 ' repeats
IF pCount = 1 THEN ' fix multiplier if needed
temp2 = 1
ENDIF
PAUSE temp1 * temp2
RETURN
' Use: Print_Str Msg
' -- Prints z-string at current position on LCD
' -- pass offset to start of z-string
Print_Str:
temp1 = __PARAM1 ' get start of string
Print_Char:
READ Pgm_Data + temp1, char ' get a character
IF char <> 0 THEN ' valid?
TX_Byte char ' yes, print
INC temp1 ' point to next
GOTO Print_Char ' go
ENDIF
RETURN
' Use: TX_Byte aChar
' -- sends 'aChar' to LCD
TX_Byte:
temp2 = __PARAM1 ' char to send
SEROUT LCD, LcdBaud, temp2 ' send to LCD
RETURN
' Use: RX_Byte @rxInput
' -- reads byte from RFID reader, puts in 'rxInput'
RX_Byte:
regAddr = __PARAM1 ' save return address
SERIN RFID, RfidBaud, temp1 ' receive a byte
__RAM(regAddr) = temp1 ' move input to addr
RETURN
' Use: Get_RFID
' -- waits for and accepts the 10-byte RFID string
Get_RFID:
LOW Enable ' enable RFID reader
RX_Byte @char ' get serial byte
IF char <> $0A THEN Get_RFID ' wait for header
FOR idx = 0 TO 9 ' rx and store RFID string
RX_Byte @char
serNum(idx) = char
NEXT
HIGH Enable ' turn reader off
RETURN
' Use: Check_Tag entry
' -- compares tag string (in array) to table entry
' -- pass offset to start of table entry
Check_Tag:
temp1 = __PARAM1 ' get tag pointer
FOR temp2 = 0 TO 9 ' compare 10 bytes
READ Pgm_Data + temp1, char ' get byte from table
IF char <> serNum(temp2) THEN ' compare bytes
tagNum = 0 ' if bad, clear tag pointer
GOTO Check_Tag_Exit ' and skip other bytes
ENDIF
INC temp1 ' point to next byte
NEXT
Check_Tag_Exit:
RETURN
The attached file will display the tag ID.
MikeS