Shop OBEX P1 Docs P2 Docs Learn Events
RFID and the SX — Parallax Forums

RFID and the SX

eagletalontimeagletalontim Posts: 1,399
edited 2010-12-08 20:32 in Accessories
I am working on a project that will help me get the ID number of each of the tags that I get in without using a computer. The device will be hand held with a 2 line 16 digit display to show me the RFID key ID. For some reason, I am not able to get the correct A-F and 0-9 characters to be displayed on the screen. I get strange characters.

Here is my code :
DEVICE          SX28, OSC4MHZ, TURBO, STACKX, OPTIONX
FREQ            4_000_000
ID              "RFID"

LcdTx           VAR     RA.2                    ' LCD serial connection
RfidEn          VAR     RA.1                    ' RFID enable control
RfidRx          VAR     RA.0                    ' RFID serial input
Lock            VAR     RB.0                    ' lock control

TagMax          CON     2                       ' three tags, (0 - 2)

LcdBaud         CON     "T19200"                ' or T2400, or T9600
RfidBaud        CON     "T2400"

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 (need 5 ms delay)
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; no crsr, no blink
LcdOn2          CON     $17                     ' LCD on; no crsr, blink on
LcdOn3          CON     $18                     ' LCD on; crsr on, no blink
LcdOn4          CON     $19                     ' LCD on; crsr on, blink on
LcdLine1        CON     $80                     ' move to line 1, column 0
LcdLine2        CON     $94                     ' move to line 2, column 0

Active          CON     0                       ' for RFID reader
Deactivated     CON     1

Open            CON     1                       ' for lock
Closed          CON     0

' -------------------------------------------------------------------------
' Variables
' -------------------------------------------------------------------------

idx1            VAR     Byte                    ' loop control
idx2            VAR     Byte
char            VAR     Byte

tagBuf          VAR     Byte(10)                ' tag bytes from reader
tagNum          VAR     Byte(10)                    ' tag number
offset          VAR     Byte

tmpB1           VAR     Byte                    ' subroutine work vars
tmpB2           VAR     Byte
tmpB3           VAR     Byte
tmpW1           VAR     Word

WATCH char
WATCH tagBuf(0)
WATCH tagBuf(1)
WATCH tagBuf(2)
WATCH tagBuf(3)
WATCH tagBuf(4)
WATCH tagBuf(5)
WATCH tagBuf(6)
WATCH tagBuf(7)
WATCH tagBuf(8)
WATCH tagBuf(9)
' =========================================================================
  PROGRAM Start
' =========================================================================

' -------------------------------------------------------------------------
' Subroutine Declarations
' -------------------------------------------------------------------------

DELAY           SUB     1, 2                    ' delay in milliseconds
LCD_OUT         SUB     1, 2                    ' byte or string to LCD
CLEAR_LCD       SUB     0                       ' clear LCD, BL is on
RX_RFID         SUB     0                       ' get char from RFID

' -------------------------------------------------------------------------
' Program Code
' -------------------------------------------------------------------------

Start:
  PLP_B = %00000001                             ' pull up unused pins
  PLP_C = %00000000

  RA = %0011                                    ' disable reader, lock it up
  TRIS_A = %0100

Main:
  CLEAR_LCD
  LCD_OUT "Present ID."
  LCD_OUT LcdLine2
  LCD_OUT LcdOn2                                ' flash block cursor

Get_Tag:
  RfidEn = Active
  DO
    char = RX_RFID
  LOOP UNTIL char = $0A                         ' wait for header    
  FOR idx1 = 0 TO 9                             ' get RFID bytes
    tagBuf(idx1) = RX_RFID
    FOR idx2 = 0 TO 15                           ' loop through characters
      READ Tags + idx2, char                  ' read tag character
      IF char = tagBuf(idx1) THEN
        LCD_OUT char
      ENDIF
    NEXT
    break
  NEXT
  RfidEn = Deactivated

  DELAY 1000
  GOTO Main

DELAY:
  IF __PARAMCNT = 1 THEN
    tmpW1 = __PARAM1                            ' save byte value
  ELSE
    tmpW1 = __WPARAM12                          ' save word value
  ENDIF
  PAUSE tmpW1
  RETURN

LCD_OUT:
  tmpB1 = __PARAM1                              ' byte or string offset
  IF __PARAMCNT = 2 THEN                        ' string specified?
    tmpB2 = __PARAM2                            '   yes, save base
    DO
      READ tmpB2 + tmpB1, tmpB3                 ' read a character
      IF tmpB3 = 0 THEN EXIT                    ' if 0, string complete
      SEROUT LcdTx, LcdBaud, tmpB3              ' send the byte
      INC tmpB1                                 ' point to next character
      tmpB2 = tmpB2 + Z                         ' update base on overflow
    LOOP
  ELSE
    SEROUT LcdTx, LcdBaud, tmpB1                ' send the byte
  ENDIF
  RETURN

CLEAR_LCD:
  LCD_OUT LcdBLon                               ' backlight on
  LCD_OUT LcdOn1                                ' no cursor or blink
  LCD_OUT LcdCls                                ' clear the LCD
  DELAY 5
  RETURN

RX_RFID:
  SERIN RfidRx, RfidBaud, tmpB1
  RETURN tmpB1

Tags:
  DATA "ABCDEF0123456789"
Sign In or Register to comment.