Shop OBEX P1 Docs P2 Docs Learn Events
Are there errors in the current version of the Basic Stamp IDE??? — Parallax Forums

Are there errors in the current version of the Basic Stamp IDE???

First off here's this:
' {$STAMP BS2}
' {$PBASIC 2.5}

'Setup I/O Pins

Clock     PIN  0                    'Shift Register Clock
SerData   PIN  1                    'Serial Data
Latch     PIN  2                    'Output Latch
Load1     PIN  3                    'Input Load 1 (Buttons)
Load2     PIN  4                    'Input Load 2 (Settings)
Audio     PIN  5                    'DTMF Output

'Con
DelayTime CON  100                  'Delay Time 1/10th sec

'Variables
Buttons   VAR  Bit(10)              'Controll Buttons
Settings  VAR  Bit(10)              'On/Off or Momentary? 1=On/Off, 0=Momentary
Relays    VAR  Bit(10)              'The Output Relays
DTMF      VAR  Nib                  '16 different DTMF Tones

'Startup
Reset:
  LOW Latch
  HIGH Load1
  HIGH Load2
  DEBUG CLS,
        "Buttons 9876543210", CR,
        "------- ----------", CR,
        "Status  ..........", CR,

'Main Program
Main:
  DO
    GOSUB Get_165A                  'Get status of buttons
    GOSUB Get_165B                  'Get status of button setup
    GOSUB RandomDTMF                'Play DTMF Tone
    'GOSUB Button0
    GOSUB Put_595                   'Update relays
    PAUSE DelayTime                 'Pause 1/10th second
  LOOP

'Subroutines
Get_165A:
  PULSOUT Load1, 5                           'Load inputs
  SHIFTIN SerData, Clock, MSBPRE, [Buttons]  'Shift in data
  RETURN

Get_165B:
  PULSOUT Load1, 5                           'Load settings
  SHIFTIN SerData, Clock, MSBPRE, [Settings] 'Shift them in
  RETURN

Put_195:
  SHIFTOUT SerData, Clock, MSBFIRST, [Relays]'Send pattern to relays
  PULSOUT Latch, 5                           'latch 595
  INPUT SerData                              'Float data lione
  RETURN

RandomDTMF:
  RANDOM  DTMF
  DTMFOUT 5, 500, 500, [DTMF]
  RETURN
I can't even start to check my program as for some odd reason the IDE will NOT let me check memory map or upload I am getting some odd errors that according to documentation, DON'T make sense... I am writing a similar program for the Propeller, but for the heck of it, decided to try my BS2 & BS2pe to do the same thing, but here is what's going on:

1) The line "Main:" I get the response "ERROR: Undefined Symbol" but the Line "Reset:" is apperently JUST FINE........ How can "Main:" have an issue when "Reset:" is fine????? And they are written the same way as the book, except for the comment lines. I know it's been quite a while since my Basic Stamp skills have been used, and I expect to screw up some, but this isn't making sense.

2) The "DO" part of the "DO.....LOOP" gets me "ERROR: Expected a constant, variable, unary operator, or '(' " I have it written the SAME way as printed in the StampWorks v2.1.pdf pg 144, with the added extra stuff written in the same format... The line "GOSUB Button0" I thought might have been an issue, the label is made but no code yet. Commented out, but no change. I saw a few errors I did, but those errors shouldn't cause this and fixed before and as I found em. So far nothing fixes this.....

The only thought's I have is the BS2 IDE is pissed off at me from not using it for few years. But I have a feeling this is probly NOT the issue. LOL :D Thanks if anyone spots what the issue is, cause I am out of ideas.........

Joe

EDIT: On " "Status ..........", CR," I removed the ", CR," and that let me check memory map, but it shouldn't effect the Do..Loop.. I know the next Debug command in the "Main:" was left out, but that shouldn't cause it.

Comments

  • Your first error message (the Main: one) looked familiar and it was. It was caused by your trailing comma after "Status ..........", CR,
    My students make that mistake a lot and so I looked for it from your descriptions.

    I then copied your program into MacBS2 and did a check syntax after deleting that comma. My only problem in your code was the GOSUB Put_595 and when I commented that line out, your program compiles fine.

    I am a teacher and all of my bots are at school right now, but your program seems fine with what I did above, so you may want to check and see if something is going on with the USB drivers.

    Hope this helps.

    Tim
  • The label MAIN: is not the issue, it's what you did just before that line, the DEBUG statement ended with a comma. I removed that and MAIN became quite acceptable. One additional error popped up, GOSUB Put_595, probably you meant 195.
    After those two errors were corrected Map and Syntax check gave their blessings to your prose.
  • Ok... Lol i dont see why it passed over that just to complain later about it, but ok. Thanks.

    Joe
  • I think I got my BS2 program done. Thanks for the help!! Now to test it out.

    Joe

    I need to go through the What is a microcontroller? Txt again..... So used to the Prop I keep screwing up....
  • jknightandkarrjknightandkarr Posts: 234
    edited 2016-03-05 07:18
    Ok, thought I was ok, now not. Noticed I used $ for my binary values, checked memory map and went through, then changed them all to % and now my Clock PIN 0 is getting the error: "Expected ':' or end-of-line." What could cause this?

    Joe

    Edit1: I changed PIN to CON, that fixed that, now my IF THEN ELSE statements are screwy. The ide telling me that ELSE being treated as a lable. I know this laptop I am using to write code not the best, but shouldn't cause these issues....

    Edit2: Ok I found the fix, some how the $ got removed from the ' {$STAMP BS2} & ' {$PBASIC 2.5} lines, so thats fixed. Probly got deleted when I changed the $ to % the laptop sometimes will move the cursor for some odd reason... Now on the IF THEN ELSE commands, does it have to be
    IF statement THEN Address
    ELSEIF Statement
    ELSE Statement
    ENDIF
    
    or can I use
    IF statement THEN Address
    ELSE Statement
    ENDIF
    

    I keep getting 'ELSE' must be preceded by 'IF' or 'CASE'

    Joe
  • jknightandkarrjknightandkarr Posts: 234
    edited 2016-03-05 07:21
    Here's my code so far.
    ' {$STAMP BS2}
    ' {$PBASIC 2.5}
    
    'Setup I/O Pins
    
    Clock     CON  0                    'Shift Register Clock
    SerData   CON  1                    'Serial Data
    Latch     CON  2                    'Output Latch
    Load1     CON  3                    'Input Load 1 (Buttons)
    Load2     CON  4                    'Input Load 2 (Settings)
    Audio     CON  5                    'DTMF Output
    
    'Con
    DelayTime CON  100                  'Delay Time 1/10th sec
    
    'Variables
    Buttons   VAR  Word                 'Controll Buttons
    Settings  VAR  Word                 'On/Off or Momentary? 1=On/Off, 0=Momentary
    Relays    VAR  Word                 'The Output Relays
    DTMF      VAR  Nib                  '16 different DTMF Tones
    
    'Startup
    Reset:
      LOW Latch
      HIGH Load1
      HIGH Load2
      Relays=%0000000000
      'DEBUG CLS,
            '"Buttons 9876543210", CR,
           ' "------- ----------", CR,
            '"Status  .........."
    
    'Main Program
    'Main:
      DO
        GOSUB Get_165A                  'Get status of buttons
        GOSUB Get_165B                  'Get status of button setup
                   '0987654321
        IF Buttons.BIT0= 1 THEN Set0
        IF Buttons.BIT1= 1 THEN Set1
        IF Buttons.BIT2= 1 THEN Set2
        IF Buttons.BIT3= 1 THEN Set3
        IF Buttons.BIT4= 1 THEN Set4
        IF Buttons.BIT5= 1 THEN Set5
        IF Buttons.BIT6= 1 THEN Set6
        IF Buttons.BIT7= 1 THEN Set7
        IF Buttons.BIT8= 1 THEN Set8
        IF Buttons.BIT9= 1 THEN Set9
        GOSUB RandomDTMF                'Play DTMF Tone
        GOSUB Put_595                   'Update relays
        PAUSE DelayTime                 'Pause 1/10th second
      LOOP
    
    'Subroutines
    Get_165A:
      PULSOUT Load1, 5                           'Load inputs
      SHIFTIN SerData, Clock, MSBPRE, [Buttons]  'Shift in data
      RETURN
    
    Get_165B:
      PULSOUT Load1, 5                           'Load settings
      SHIFTIN SerData, Clock, MSBPRE, [Settings] 'Shift them in
      RETURN
    
    Put_595:
      SHIFTOUT SerData, Clock, MSBFIRST, [Relays]'Send pattern to relays
      PULSOUT Latch, 5                           'latch 595
      INPUT SerData                              'Float data lione
      RETURN
    
    RandomDTMF:
      RANDOM  DTMF
      DTMFOUT Audio, 500, 500, [DTMF]
      RETURN
    
    Set0:
      IF (Settings.BIT0= 1) THEN Onoff0
      ELSE
        Momentary0
      ENDIF
      RETURN
    
    Set1:
      IF (Settings.BIT1= 1) THEN Onoff1
      ELSE
        Momentary1
      ENDIF
      RETURN
    
    Set2:
      IF (Settings.BIT2= 1) THEN Onoff2
      ELSE
        Momentary2
      ENDIF
      RETURN
    
    Set3:
      IF (Settings.BIT3= 1) THEN Onoff3
      ELSE
        Momentary3
      ENDIF
      RETURN
    
    Set4:
      IF (Settings.BIT4= 1) THEN Onoff4
      ELSE
        Momentary4
      ENDIF
      RETURN
    
    Set5:
      IF (Settings.BIT5= 1) THEN Onoff5
      ELSE
        Momentary5
      ENDIF
      RETURN
    
    Set6:
      IF (Settings.BIT6= 1) THEN Onoff6
      ELSE
        Momentary6
      ENDIF
      RETURN
    
    Set7:
      IF (Settings.BIT7= 1) THEN
        Onoff7
      ELSE
        Momentary7
      ENDIF
      RETURN
    
    Set8:
      IF (Settings.BIT8= 1) THEN Onoff8
      ELSE
        Momentary8
      ENDIF
      RETURN
    
    Set9:
      IF (Settings.BIT9= 1) THEN Onoff9
      ELSE
        Momentary9
      ENDIF
      RETURN
    
    Onoff0:
      TOGGLE Relays.BIT0
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT0= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff1:
      TOGGLE Relays.BIT1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT1= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff2:
      TOGGLE Relays.BIT2
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT2= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff3:
      TOGGLE Relays.BIT3
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT3= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff4:
      TOGGLE Relays.BIT4
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT4= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff5:
      TOGGLE Relays.BIT5
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT5= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff6:
      TOGGLE Relays.BIT6
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT6= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff7:
      TOGGLE Relays.BIT7
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT7= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff8:
      TOGGLE Relays.BIT8
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT8= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Onoff9:
      TOGGLE Relays.BIT9
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT9= 0)
        PAUSE 250
      LOOP
      RETURN
    
    Momentary0:
      Relays.BIT0= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT0= 0)
        PAUSE 250
      LOOP
      Relays.BIT0= 0
      RETURN
    
    Momentary1:
      Relays.BIT1= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT1= 0)
        PAUSE 250
      LOOP
      Relays.BIT1= 0
      RETURN
    
    Momentary2:
      Relays.BIT2= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT2= 0)
        PAUSE 250
      LOOP
      Relays.BIT2= 0
      RETURN
    
    Momentary3:
      Relays.BIT3= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT3= 0)
        PAUSE 250
      LOOP
      Relays.BIT3= 0
      RETURN
    
    Momentary4:
      Relays.BIT4= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT4= 0)
        PAUSE 250
      LOOP
      Relays.BIT4= 0
      RETURN
    
    Momentary5:
      Relays.BIT5= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT5= 0)
        PAUSE 250
      LOOP
      Relays.BIT5= 0
      RETURN
    
    Momentary6:
      Relays.BIT6= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT6= 0)
        PAUSE 250
      LOOP
      Relays.BIT6= 0
      RETURN
    
    Momentary7:
      Relays.BIT7= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT7= 0)
        PAUSE 250
      LOOP
      Relays.BIT7= 0
      RETURN
    
    Momentary8:
      Relays.BIT8= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT8= 0)
        PAUSE 250
      LOOP
      Relays.BIT8= 0
      RETURN
    
    Momentary9:
      Relays.BIT9= 1
      GOSUB RandomDTMF                'Play DTMF Tone
      DO UNTIL (Buttons.BIT9= 0)
        PAUSE 250
      LOOP
      Relays.BIT9= 0
      RETURN
    

    Joe
  • You are calling subroutines incorrectly. Each call must be preceded with the command GOSUB. For instance, in your function Set0:
    Set0:
      IF (Settings.BIT0= 1) THEN Onoff0
      ELSE
        Momentary0
      ENDIF
      RETURN
    

    I made the following changes and Syntax Check doesn't gripe;
    Set0:
      IF (Settings.BIT0= 1) THEN
        GOSUB Onoff0
      ELSE
        GOSUB Momentary0
      ENDIF
      RETURN
    

    In your posting there are many more of these errors.

    I can't tell why moving the GOSUB Onoff0 to a separate line makes it work, but it does.

    Hal

  • Ok. I will add them. The documentation don't mention using the GOSUB in that. Lol Thanks.

    Joe
  • The BASIC Stamp Editor defaults to PBASIC 2.0 if it doesn't recognize a PBASIC 2.5 directive.
    On page 474 of the BASIC Stamp Reference Manual (page 478 of the PDF) is a chart that shows which commands were added in PBASIC 2.5.

    The Stamps-In-Class text "Industrial Control" was written in PBASIC 2.0 and the program flow is much more "spaghetti"-like compared with the later written "Process Control".
    IF...THENs would "jump" to another place in the program and GOTO Main or Loop was also common.
Sign In or Register to comment.