Shop OBEX P1 Docs P2 Docs Learn Events
Crazy Code help — Parallax Forums

Crazy Code help

GiuseppeGiuseppe Posts: 51
edited 2009-03-04 04:03 in BASIC Stamp
I tried my first attempt at trying to make my bs2 try to learn an rfid tag with the parallax rfid reader. I seem to be having some trouble


' {$STAMP BS2}
' {$PBASIC 2.5}

'-------[noparse][[/noparse] I/O Definitions ]-----------------------------------------------------------------------------------------

RX                 PIN       0
Enable             PIN       1
Beep               PIN       2
GreenLED           PIN       3
YellowLED          PIN       4
Starter            PIN       5
RedLED             PIN       6
DoorWire1          PIN       9
DoorWire2          PIN       10

'------[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     1


#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

Beeps       VAR       Nib

mysterytag  VAR       Word
datalog     VAR       Word

'------[noparse][[/noparse] EEPROM Data ]----------------------------------------------------------------------------------------------

'Tag1            DATA    "0F03029F09"            ' valid tag

'------[noparse][[/noparse] Select Mode ]------------------------------------------------------------------------------------------------

DO

  SELECT mode

    CASE = 0
      GOTO Reset
    CASE = 1
      GOSUB Program
  ENDSELECT

LOOP

'------[noparse][[/noparse] Initialization ]-------------------------------------------------------------------------------------------

Reset:

  HIGH      Enable                    ' turn off RFID reader
  LOW       DoorWire1                 ' sends lock pulse to respective wire
  HIGH      DoorWire2                 ' sends lock pulse to respective wire
  PAUSE     2000                      ' pulse length is a quarter second
  INPUT     DoorWire1                 ' pulse ends for respective wire
  INPUT     DoorWire2                 ' pulse ends for respective wire

'------[noparse][[/noparse] Program Code ]---------------------------------------------------------------------------------------------

Main:
  LOW  Enable                                   ' activate the reader
  HIGH RedLED

DO
  SERIN Rx, 2400, [noparse][[/noparse]mysterytag]

  IF mysterytag = datalog THEN
    GOTO Tag_Found
  ELSE
  ENDIF
LOOP

  '#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

  'FOR Beeps = 0 TO 10
  '  FREQOUT     Beep, 250, 4500
 ' NEXT

 ' GOTO Main

  Tag_Found:
    FREQOUT   Beep, 500, 4500           ' confirmation beep

    HIGH      DoorWire1                 ' sends unlock pulse for respective wire
    LOW       DoorWire2                 ' sends unlock pulse for respective wire
    PAUSE     2000                      ' pulse length is a quarter second
    INPUT     DoorWire1                 ' pulse ends for respective wire
    INPUT     DoorWire2                 ' pulse ends for respective wire

    LOW       RedLED                    ' red LED turns off

    HIGH      Starter                   ' starter wire connects
    HIGH      GreenLED                  ' green LED turns on
    PAUSE     20000                     ' program pauses for 20 seconds

    LOW       GreenLED                  ' green LED turns off
    HIGH      YellowLED                 ' yellow LED turns on signaling 20 seconds have passed
    PAUSE     10000                     ' program pauses for 10 seconds

    LOW       YellowLED                 ' yellow LED turns off
    LOW       Starter                   ' starter wire breaks

    LOW       DoorWire1                 ' sends lock pulse to respective wire
    HIGH      DoorWire2                 ' sends lock pulse to respective wire
    PAUSE     2000                      ' pulse length is a quarter second
    INPUT     DoorWire1                 ' pulse ends for respective wire
    INPUT     DoorWire2                 ' pulse ends for respective wire

    FOR Beeps = 0 TO 1
      FREQOUT   Beep, 150, 4500
    NEXT

  GOTO Main

  '----------------[noparse][[/noparse] Programming Mode ]--------------------------------------

  Program:
    SERIN Rx, 2400, [noparse][[/noparse]datalog]
    WRITE 100, datalog
  GOTO Reset




My first time really trying to incorporate the WRITE and SERIN commands. I am still trying to fix myself, any hints appreciated.

Comments

  • GiuseppeGiuseppe Posts: 51
    edited 2009-03-04 04:03
    To make this easier to look at, all I really want to do is program the rfid tag into a variable in the "program" section by using

    Program:
        SERIN Rx, 2400, [noparse][[/noparse]datalog]
        WRITE 100, datalog
      GOTO Reset
    
    



    Then when that variable is written on the BS2, I wanted to make it compare 'datalog' (the written tag) to 'mysterytag' (the tag being presented when entry is desired) by the code that follows

    
    SERIN Rx, 2400, [noparse][[/noparse]mysterytag]
    
    DO
      IF mysterytag = datalog THEN
        GOTO Tag_Found
      ELSE
      ENDIF
    LOOP
    
    



    Perhaps part of the source I commented out had something important to it that I did not take into account?
Sign In or Register to comment.