' ========================================================================= ' ' File....... RFID_DPRG_Demo.BS2 ' Purpose.... RFID Tag Reader / Simple Security System ' Author..... (c) Parallax, Inc. -- All Rights Reserved ' E-mail..... support@parallax.com ' Started.... ' Updated.... 12 FEB 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 4 ' speaker output LCD PIN 15 ' -----[ Constants ]------------------------------------------------------- #SELECT $STAMP #CASE BS2, BS2E T2400 CON 396 T9600 CON 84 T19K2 CON 32 TmAdj CON $100 ' x 1.0 (time adjust) FrAdj CON $100 ' x 1.0 (freq adjust) #CASE BS2SX T2400 CON 1021 T9600 CON 240 T19K2 CON 110 TmAdj CON $280 ' x 2.5 FrAdj CON $066 ' x 0.4 #CASE BS2P T2400 CON 1021 T9600 CON 240 T19K2 CON 110 TmAdj CON $3C5 ' x 3.77 FrAdj CON $044 ' x 0.265 #CASE BS2PE T2400 CON 396 T9600 CON 84 T19K2 CON 32 TmAdj CON $100 ' x 1.0 FrAdj CON $0AA ' x 0.665 #ENDSELECT 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 LcdCC0 CON $F8 ' define custom char 0 LcdCC1 CON $F9 ' define custom char 1 LcdCC2 CON $FA ' define custom char 2 LcdCC3 CON $FB ' define custom char 3 LcdCC4 CON $FC ' define custom char 4 LcdCC5 CON $FD ' define custom char 5 LcdCC6 CON $FE ' define custom char 6 LcdCC7 CON $FF ' define custom char 7 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 ]----------------------------------------------------- Tag1 DATA "0F0184F20B" ' valid tags Tag2 DATA "0F01D9D263" Tag3 DATA "04129C1B43" Name0 DATA "Unauthorized ", 0 Name1 DATA "Dale Wheat ", 0 Name2 DATA "Ron Grant ", 0 Name3 DATA "Martin Meier ", 0 Title0 DATA "Access Denied ", 0 Title1 DATA "President ", 0 Title2 DATA "Vice President ", 0 Title3 DATA "Treasurer ", 0 ' -----[ Initialization ]-------------------------------------------------- Reset: HIGH Enable ' turn of RFID reader PAUSE 100 GOSUB Banner ' -----[ Program Code ]---------------------------------------------------- Main: LOW Enable ' activate the reader #SELECT $STAMP #CASE BS2, BS2E SERIN RX, T2400, 1000, No_Tag, [WAIT($0A), STR buf\10] #CASE BS2SX SERIN RX, T2400, 2500, No_Tag, [WAIT($0A), STR buf\10] #CASE BS2P SERIN RX, T2400, 2500, No_Tag,[WAIT($0A), SPSTR 10] #CASE BS2PE SERIN RX, T2400, 1000, No_Tag,[WAIT($0A), SPSTR 10] #ENDSELECT 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 GOSUB Show_Title FREQOUT Spkr, 1000 */ TmAdj, 115 */ FrAdj ' groan PAUSE 1000 GOTO Main Tag_Found: GOSUB Show_Name ' print name GOSUB Show_Title FREQOUT Spkr, 2000 */ TmAdj, 880 */ FrAdj ' beep GOTO Main No_Tag: HIGH Enable GOSUB Banner PAUSE 500 GOTO Main END ' -----[ Subroutines ]----------------------------------------------------- ' Prints name associated with RFID tag Show_Name: SEROUT LCD, T19K2, [LcdLine1] 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 SEROUT LCD, T19K2, [char] ' otherwise print it idx = idx + 1 ' point to next character LOOP RETURN Show_Title: SEROUT LCD, T19K2, [LcdLine2] LOOKUP tagNum, [Title0, Title1, Title2, Title3], idx ' point to first character DO READ idx, char ' read character from name IF (char = 0) THEN EXIT ' if 0, we're done SEROUT LCD, T19K2, [char] ' otherwise print it idx = idx + 1 ' point to next character LOOP RETURN Banner: SEROUT LCD, T19K2, [LcdOn1, LcdLine1, " DPRG SECURITY ", LcdLine2, REP " "\16] RETURN