Shop OBEX P1 Docs P2 Docs Learn Events
I need help with my code. — Parallax Forums

I need help with my code.

qazxsw21000qazxsw21000 Posts: 13
edited 2011-11-20 06:36 in BASIC Stamp
' {$STAMP BS2}' {$PBASIC 2.5}


z VAR Byte
y VAR Byte
x VAR Byte


HIGH 0
PAUSE 500
a:
LOW 0
SERIN 1, 2400,[x]
HIGH 0


READ 0,y
IF x=y THEN
TOGGLE 11:TOGGLE 13
ENDIF
IF x<>y THEN
READ 1,z
ENDIF


IF x=z THEN
TOGGLE 11:TOGGLE 13
ENDIF
IF x<>z THEN
HIGH 15
PAUSE 500
LOW 15
ENDIF
PAUSE 250
GOTO a

It'll read the tags and EEPROM. But it won't compare the variables.

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2011-11-17 17:36
    First of all, the Baud constant in the SERIN statement is not the Baud itself, it's a 16-bit value calculated from the Baud plus some bits for normal / inverted and 7-bit with parity vs. 8-bit. Look in the Stamp Editor's help files or the Basic Stamp Syntax and Reference Manual for details. If you can't read the data properly, you can't compare it successfully.

    Before you ask again, please add some comments to your program that explain what you're trying to do. It helps you and it helps us help you. Also note that the compiler directives at the beginning each have to be on their own lines.
  • qazxsw21000qazxsw21000 Posts: 13
    edited 2011-11-20 06:36
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    z VAR Byte
    y VAR Byte
    x VAR Byte
    
    
    HIGH 0                                'Disable RFID device
    PAUSE 500                             'Wait 500ms
    a:
    LOW 0                                 'Enable RFID device
    SERIN 1, 396,[x]                      'Read serial data from RFID device
    HIGH 0                                'Disable RFID device
    
    
    READ 0,y                              'Read value stored in address 0, store as "y"
    IF x=y THEN                           'Compare stored value and tag value, if equal
    TOGGLE 11:TOGGLE 13                   'Change logic state of pins 11 and 13
    ENDIF
    IF x<>y THEN                          'If tag value does not equal stored value
    READ 1,z                              'Read address 1, store as "z"
    ENDIF
    
    
    IF x=z THEN                           'If tag value equals stored value
    TOGGLE 11:TOGGLE 13                   'Change logic state of pins 11 and 13
    ENDIF
    IF x<>z THEN                          'If tag value does not equal stored value
    HIGH 15                               'Change state of pin 15 to logic 1
    PAUSE 500                             'Wait 500ms
    LOW 15                                'Change pin 15 back to logic state 0
    ENDIF
    PAUSE 250                             'Wait 250ms
    GOTO a                                'Go back to a
    
    Is that better? If the directives are still on one line, I don't know why. They're on two.
Sign In or Register to comment.