Shop OBEX P1 Docs P2 Docs Learn Events
updated-program — Parallax Forums

updated-program

ArchiverArchiver Posts: 46,084
edited 2001-01-09 12:08 in General Discussion
hello again :-)

here is my program now, pretty much the same but implementing the
branch statement as several of you suggested instead of the IF..THEN
statements i previously used....

i'm trying to write a program for the BS2 where i connect LED's to the
pins to demonstrate the algorithm i programmed in. When i built this i
will have actual external circuits connected to the pins but for now
i just want to have the controller run through different scenarios

any suggestion would be great.....

'=== constanst and pin
motion con pin 0
noise con pin 1
glass con pin 2
door con pin 3
buzz con pin 7
light con pin 8
light1 con pin 9

alarms var nibble
motion var alarms.bit0
noise var alarms.bit1
glass var alarms.bit2
door var alarms.bit3

motion = 0
noise = 1
glass = 1
door = 0

GOSUB check

motion = 1
noise = 0
glass = 1
door = 1

GOSUB check

motion = 1
noise = 1
glass = 1
door = 1

GOSUB check

end

check:
Branch INA,[noparse][[/noparse]check,,message,message,alarm,message,alarm,alarm,alarm,light]
RETURN

LED:
low light
pause 250
high light
RETURN

Message:
FOR counter 0 to 3
GOSUB blink
NEXT

blink:
low light1
pause 50
high light1
pause 50
RETURN

Alarm:
low buzz
pause 50
high buzz
RETURN


does this look correct? i'm confused about the declaring the direction
of the pins and the input and output pins?? i have the scott edwards book
and the manual from the website but it's not clear to me

saying low light -- does that automatically make it a output?

also my friend told me to be careful when touching the stamp ....
something about it being static sensitive or something and the static
in my body.... do i have to be careful or do something before i touch
the carrier board?? Will i damage the chip if i have too much static
in me or something??

thanks for your patience.... my questions must seem soooo basic to
most of you.... :-)

ps- i'm actually a student trying to use the stamp in my senior
design project... for my home security system..

- LaQuida

Comments

  • ArchiverArchiver Posts: 46,084
    edited 2001-01-08 08:34
    Hi LaQuida,

    >motion con pin 0
    >noise con pin 1
    >glass con pin 2
    >door con pin 3
    >buzz con pin 7
    >light con pin 8
    >light1 con pin 9

    The syntax is wrong. (The BS2 does not use the word PIN.) Your
    outputs are buzz, light and light1. Use the following syntax:
    buzz con 7
    light con 8
    light1 con 9

    Then
    low buzz
    yes, that will turn P7 into an output, and makes it low.

    The other constants, motion, noise, glass and door are inputs in your
    program. That syntax there is wrong too. The way to give another
    name to an input pin is the following, using alias name:

    motion var in0 ' when used as a variable, as in [noparse][[/noparse]if motion=0 then alarm]
    or
    motion_pin con 0 ' as a pin reference, as in [noparse][[/noparse]pulsin motion_pin,0,x]
    etc


    But if you do that, you can't use the same names as part of a
    variable, as you did nicely later in your program:

    >alarms var nibble
    >motion var alarms.bit0
    >noise var alarms.bit1
    >glass var alarms.bit2
    >door var alarms.bit3

    I like that. Then you can command:

    alarms=inA ' to get the current value at the input port
    ' or use your test patterns, like [noparse][[/noparse]alarms=1111]
    Branch alarms,[noparse][[/noparse]check,,message,message,alarm,message,alarm,alarm,alarm,light]


    You might want to start off your program with a couple of statements
    that define all your outputs and inputs:

    outs=%1110000000 ' makes buzz, light and light1 outputs, high to start.
    dirs=%1110000000 ' and all other pins inputs to start.

    good luck,
    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-08 18:30
    out=%11100000
    dir=%11100000

    is this saying that every pin is an output so i don't have to specify any
    inputs??

    i don't have to name them either?

    if i use the same code below where i say

    alarms var nibble
    motion var alarms.bit0
    noise var alarms.bit1 ...

    i don't have to specify which set of 4 pins are going to hold the alarms?
    only specify the pins for the outputs i have to send a signal out to another
    circuit?



    >===== Original Message From basicstamps@egroups.com =====
    >Hi LaQuida,
    >
    >>motion con pin 0
    >>noise con pin 1
    >>glass con pin 2
    >>door con pin 3
    >>buzz con pin 7
    >>light con pin 8
    >>light1 con pin 9
    >
    >The syntax is wrong. (The BS2 does not use the word PIN.) Your
    >outputs are buzz, light and light1. Use the following syntax:
    > buzz con 7
    > light con 8
    > light1 con 9
    >
    >Then
    > low buzz
    >yes, that will turn P7 into an output, and makes it low.
    >
    >The other constants, motion, noise, glass and door are inputs in your
    >program. That syntax there is wrong too. The way to give another
    >name to an input pin is the following, using alias name:
    >
    > motion var in0 ' when used as a variable, as in [noparse][[/noparse]if motion=0 then
    alarm]
    >or
    > motion_pin con 0 ' as a pin reference, as in [noparse][[/noparse]pulsin motion_pin,0,x]
    > etc
    >
    >
    >But if you do that, you can't use the same names as part of a
    >variable, as you did nicely later in your program:
    >
    >>alarms var nibble
    >>motion var alarms.bit0
    >>noise var alarms.bit1
    >>glass var alarms.bit2
    >>door var alarms.bit3
    >
    >I like that. Then you can command:
    >
    >alarms=inA ' to get the current value at the input port
    > ' or use your test patterns, like [noparse][[/noparse]alarms=1111]
    >Branch alarms,[noparse][[/noparse]check,,message,message,alarm,message,alarm,alarm,alarm,light]
    >
    >
    >You might want to start off your program with a couple of statements
    >that define all your outputs and inputs:
    >
    > outs=%1110000000 ' makes buzz, light and light1 outputs, high to start.
    > dirs=%1110000000 ' and all other pins inputs to start.
    >
    > good luck,
    > -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-08 18:38
    can i use this syntax

    alarms.bit0 con 0
    alarms.bit1 con 1
    alarms.bit2 con 2
    alarms.bit3 con 3
    light con 7
    message con 8
    light1 con 9

    alarms var nibble
    motion var alarms.bit0
    noise var alarms.bit1
    glass var alarms.bit2
    door var alarms.bit3

    do i need to specify which direction everything is ? what's an input and
    output?

    out = %00000001110000000
    dir = &00000001110000000

    so 16 I/O's all together and only 7, 8, and 9 are outputs?
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-08 19:33
    Do you have a stamp to experiment with?

    I suggest that you try out a few short programs before you get too
    deep into writing a your complicated program. Here are a few
    resources that can help:
    - the recently updated FAQ from <www.parallaxinc.com>
    - Scott Edwards' book, "Programming and Customizing the BASIC Stamp"
    - "What is a Microcontroller" text downloadable from
    <www.stampsinclass.com>.
    - the version 2.0 manual downloadable from <www.parallaxinc.com>
    (try the examples)
    - the new Microcontroller Allication Cookbook from Parallax

    >alarms var nibble
    >motion var alarms.bit0
    >noise var alarms.bit1
    >glass var alarms.bit2
    >door var alarms.bit3
    >
    >alarms.bit0 con 1
    >alarms.bit1 con 2
    >alarms.bit2 con 3
    >alarms.bit3 con 4

    The second group of definitions is bad syntax. You can't redefine
    variables, much less chunks of variables. STAMP2W.EXE will tell you
    that that is a syntax error. That is why you need to build your
    program a little bit at a time.

    Here is another snippet from one of the programs you posted:

    >alarms = [noparse][[/noparse]0100]
    >GOSUB check
    >
    >end
    >
    >check:
    >alarms =INA
    >Branch INA,[noparse][[/noparse]check,,message,message,alarm,message,alarm,alarm,alarm,light]
    >RETURN


    When the program hits the check subroutine, it will read the input
    port A (The four bits for your security inputs) and put those values
    in the variable alarm., replacing the value you put there in the
    earlier statement. Then the Branch command ignores the value of
    alarms anyway, and instead acts directly on the state of the input
    port. Here is a modification:

    alarms = %0100 <---note the change in syntax
    GOSUB check

    alarms =INA
    GOSUB check

    end

    check:
    Branch alarms,[noparse][[/noparse]check,,message,message,alarm,message,alarm,alarm,alarm,light]
    RETURN

    You see, the Branch now uses alarms, so that you can use either your
    fabricated test data, or, by setting alarms=inA, the actual data at
    the input port. Note also the %0100 form of the binary data.

    Please, before you ask any more (specific) questions, try to run some
    simple programs interactively from the reference materials. I think
    then things will make more sense then. The syntax is not too
    difficult, but like most computer languages, it is picky.

    good luck,
    -- Tracy
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-08 20:24
    > - the recently updated FAQ from <www.parallaxinc.com>


    Don't forget the unofficial FAQ at
    http://www.al-williams.com/wd5gnr/stampfaq.htm

    Regards,

    Al Williams
    AWC
    * Floating point math for the Stamp, PIC, SX, or any microcontroller at
    http://www.al-williams.com/awce/pak1.htm
  • ArchiverArchiver Posts: 46,084
    edited 2001-01-09 12:08
    >> - the recently updated FAQ from <www.parallaxinc.com>
    >
    >
    >Don't forget the unofficial FAQ at
    >http://www.al-williams.com/wd5gnr/stampfaq.htm
    >

    Or Microcontroller Projects with Basic Stamps by Al Williams [noparse]:)[/noparse]
Sign In or Register to comment.