November 25, 2024, 09:17:55 AM

News:

Be sure to checkout our Vixen interfaces in the Library forum -- if you want PC automation at near zero cost, EFX-TEK and Vixen is a great combination of tools.


prop-1 variable chart on page #7 explanation

Started by Chanter, September 15, 2007, 07:04:59 AM

Previous topic - Next topic

Chanter

September 15, 2007, 07:04:59 AM Last Edit: September 15, 2007, 07:16:27 AM by Chanter
I just bought the prop-1 and used the prop -1 trainer.  I read the programming basics book and have gone over several of the listed programs on-line.  However, the variables chart on page #7 is confusing to me.  I understand pin0-pin7 & dir0-dir7, but what is w0-w5 & b0-b13?

for example:

'-----[ variables ]---------------------------------

symbol idx    = B2
symbol delay    = W4
symbol lottery  = w5

also, can you help explain these codes for me?

'----- [ initialization ]-----------------------------------

reset:

dirs = %00000111
lottery = 1031

Thanks for the help!






livinlowe

On that chart, it is showing that the Prop-1 has 6 "word" variables (Word being shortened to W, hence W0,W1,ect). A word sized variable has 8 bits or %00000000. You can break a word into "Bytes", which have 4 bits and are called the high and low bytes. So, the chart is simply showing that the prop-1 can have 6 word sized variables, or 12 byte sized variables. This is a generalization, as W6 is used internal to the prop-1 to record how many gosubs/returns you use, so really you have 5 word variables, or 10 byte variables you can use in your programs.

Hope I got that right... ::)
Shawn
Scaring someone with a prop you built -- priceless!

JonnyMac

The BASIC Stamp manual and Help File (which is part of the BASIC Stamp editor) has a detailed explanation on memory, so let me give an overview and some hints.

In our programs we have three kinds of values: I/O pins (or their registers), constants (values that don't change), and variables (values that do change).  In PBASIC1, all values are declared with the SYMBOL directive, and in truth, we use SYMBOL to give useful names to items so that our programs are easier to read and maintain.

Here's an example where we need a variable:

Flasher:
  FOR flashes = 1 TO 10
    HIGH Led
    PAUSE 100
    LOW Led
    PAUSE 100
  NEXT


In this snippet we're using FOR-NEXT which needs a control variable to hold the count (1 to 10) contents while the loop runs.  We would typically define the variable like this:

SYMBOL  flashes         = B2

What we're doing with this definition is renaming the byte value at RAM address 2 to "flashes" to make it easier to use in the program. 

The Prop-1 has 14 bytes of "user RAM" -- these are the variables that we can use in our programs to control things.  These bytes have the internal names B0-B13.  We can use these names but they don't mean anything except their size and address, and giving them useful names with SYMBOL is always a good idea. 

Now, two bytes can be combined to create a word, and internally the Prop-1 recognizes seven word variables, W0-W6.  What's important to understand is that the word variables are overlaid on top of the byte variables -- like this:

W0 = B0  / B1   *
W1 = B2  / B3
W2 = B4  / B6
W3 = B6  / B7
W4 = B8  / B9
W5 = B10 / B11
W6 = B12 / B13  *

What this means is that a change to W0 could change B0, B1 or both.  And a change to B0 or B1 will change W0.  Note the asterisks above.  B0 and B1 allow bit access so I suggest these not be used unless needed; B12 and B13 are used as a subroutine stack, so you can't use these bytes in programs that have GOSUBs.

The "B" variables can hold values from 0 to 255; the "W" variables can hold values from 0 to 65535 -- so make your assignments accordingly.  When I'm writing programs I start my byte declarations at B2 (saving B0 and B1 for bit access if I need it later) and work up (B3, B4 ...), and my word declarations at W5 and work down (W4, W3, ...).  What we have to be careful of with the Prop-1 is cross-assigning to variables to the same RAM location; for example:

SYMBOL  counter         = B10
SYMBOL  lottery         = W5


These definitions could present a problem in that "counter" is in the same RAM location as the low byte of "lottery" so changing "counter" will change "lottery" and a change in the low byte of "lottery" will change "counter."  The BASIC Stamp editor has a memory map feature that shows how the assignments graphically so use this until you get the hang of things.
Jon McPhalen
EFX-TEK Hollywood Office

Chanter

Ok, thank you.  I'll get the hang of this in a short time.  I went to the Basic Stamp Editor under help, this has a lot of good info.