Shop OBEX P1 Docs P2 Docs Learn Events
Selecting the appropriate device in code — Parallax Forums

Selecting the appropriate device in code

NewBeeNewBee Posts: 35
edited 2010-06-18 19:18 in BASIC Stamp
Can someone please point me to a paper that tells me how to read this code?

Thanks,

Bob

#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

Comments

  • sylvie369sylvie369 Posts: 1,622
    edited 2010-06-18 16:05
    I can give you a brief explanation. It's "conditional compilation directives", which you can read about in the PBASIC help system.

    The purpose of this particular code is to allow PBASIC code that contains serial I/O to run with any of the Basic Stamp modules. If you look at (for example) the SERIN and SEROUT help pages in the PBASIC help system, you'll see that the code number for a particular serial baud rate depends on the kind of Stamp you're using. If you use the wrong code for your Stamp, you simply won't be able to communicate through the serial commands. These conditional directives tell the PBASIC code which baud code to use once it knows which Stamp module you're using.

    Post Edited (sylvie369) : 6/18/2010 4:10:05 PM GMT
  • NewBeeNewBee Posts: 35
    edited 2010-06-18 16:35
    Ok, Thank you.· This code does not seem to properly initialize the 2p40 snd it is conspicuously absent from the select list.· Thoughts?
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-06-18 16:48
    Hmm. I've never used a 2p40, but I had assumed it would work just like the 2p as far as serial communications go.
    When you say it "does not seem to properly initialize", what do you mean? What is it doing/not doing?

    You do have a #STAMP directive for the 2p at the top of your code, right? You should have two lines that look like this:

    ' {$STAMP BS2p}
    ' {$PBASIC 2.5}
    


    ...which you get by clicking the little yellow Stamp icon and the "2.5" icon up at the top of the PBASIC environment.

    Suggestion: if you know you are only going to use your code with the 2p40, you could get rid of most of that, and just leave this part:

        T1200       CON     2063
        T2400       CON     1021
        T4800       CON     500
        T9600       CON     240
        T19K2       CON     110
        TMidi       CON     60
        T38K4       CON     45
    

    (that's the constants as defined in the 2p section of the conditionals).

    In fact, if you knew in advance which baud rate you're using, you could simply use that one constant, and ignore all of the other code. You could reduce all of that to one line of constant declaration.
  • NewBeeNewBee Posts: 35
    edited 2010-06-18 18:52
    I've got it, thank you.·Still learning, Sample code from StampWorks 2.1 exercise 34 missing DIRD initialization for serial I/O· and I'm debugging oneside at a time so I forgot to simulate flow control.

    Again, thanks for your·help.

    ·
  • sylvie369sylvie369 Posts: 1,622
    edited 2010-06-18 19:18
    Good to hear it. Have fun.
Sign In or Register to comment.