RFID code help
Maybe this is asking too much but could someone walk me through what is exactly happening with this example source code. I am still a newbie to understanding what some of this stuff means.
Or maybe there is documentation somewhere I can further study?
' ========================================================================= ' ' File....... RFID_basic.BS2 ' Purpose.... RFID Tag Reader ' Author..... (c) Parallax, Inc. -- All Rights Reserved ' E-mail..... support@parallax.com ' Started.... ' Updated.... 02 Mar 2005 ' ' {$STAMP BS2} ' {$PBASIC 2.5} ' ' ========================================================================= ' -----[noparse][[/noparse] Program Description ]--------------------------------------------- ' ' Reads tags from a Parallax RFID reader and displays ID to debug screen ' -----[noparse][[/noparse] Revision History ]------------------------------------------------ ' -----[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 T2400 CON 396 #CASE BS2SX, BS2P T2400 CON 1021 #CASE BS2PX T2400 CON 1646 #ENDSELECT Baud CON T2400 LastTag CON 3 #DEFINE __No_SPRAM = ($STAMP < BS2P) ' does module have SPRAM? ' -----[noparse][[/noparse] Variables ]------------------------------------------------------- #IF __No_SPRAM #THEN buf VAR Byte(10) ' RFID bytes buffer #ELSE Char VAR Byte ' character to test #ENDIF tagNum VAR Nib ' from EEPROM table idx VAR Byte ' tag byte index ' -----[noparse][[/noparse] Initialization ]-------------------------------------------------- Reset: HIGH Enable ' turn of RFID reader ' -----[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 Display_Tag: DEBUG "Tag Identification number is: ", CR FOR idx = 0 TO 9 ' scan bytes in tag #IF __No_SPRAM #THEN DEBUG buf(idx) #ELSE GET idx, Char ' read char from SPRAM DEBUG Char #ENDIF NEXT DEBUG CR PAUSE 500 GOTO main ' repeats code
Or maybe there is documentation somewhere I can further study?
Comments
All the lines beginning with ' are comments: these are for the programmers eyes, and they have absolutely no effect on code operation.
The section under I/O definitions allows you to name a pin so that other code is more easily read.
The section under constants allows you to name constants. Wherever you see LastTag in the program, you can replace it with 3 and there is no difference in execution.
The section under variables declares named variables.
The initialization turns off the RFID reader.
The Main: is a program label. Everything below that (before the next label) is a logical block of code that is "main" in some way. In this case, it receives information from the RFID reader and stores it in a ram location.
The Display_tag: program label is the logical block of code that displays the tag, in this case on your computer screen.
For more information about PBASIC, see the books "What's a microcontroller" and "PBASIC syntax and Reference Manual" available from the parallax main website for free download.