Shop OBEX P1 Docs P2 Docs Learn Events
basic analog to digital course queston — Parallax Forums

basic analog to digital course queston

bnrgbnrg Posts: 14
edited 2011-01-04 14:10 in BASIC Stamp
Hi,
I have been working thru the basic analog to digital course-it is pretty interesting and is just what I was looking for. One point that I don't understand relates to the addressing section on page 79-what is the reasoning behind the "15" after the DIRB as shown below?

DAC:
DIRB = 15
OUTB = n
return

"n" is set by the "FOR n = 0 to 15" in the main program (16 values as it has 4 bit resolution) and changing the DIRB value to other than 15 results in lower overall voltage values from the resistor network, but I don't see (and could not find in the basic stamp manual) what criteria is used to select the DIRB value.

Thanks,
Bob

Comments

  • vaclav_salvaclav_sal Posts: 451
    edited 2011-01-04 12:30
    DIRB = 15 sets B nibble of I/O register to output mode.
    All BS I/O "pins" are initialized to 0 = input on power up.
    This info is burried in "memory organization" section of the software manual.
  • Spiral_72Spiral_72 Posts: 791
    edited 2011-01-04 14:10
    Like already said:

    DIR = sets the data direction of the pins in question. 0 = input, 1 = output
    B = Corresponds to P4 to P7....... the "B" nibble
    15 = the number sent to the direction control. 15 is decimal, it can also be written as $F in hex, OR!!!! 1111 IN BINARY!

    Do you see what the 15 means yet? 15 in binary is 1-1-1-1, so P4 = 1, P5 = 1, P6 = 1 and P7 = 1

    You could write it as:
    DIRB = 15
    DIRB = $F
    DIRB = %1111

    They all do the same. The binary form in this case makes a little more sense..... it's easier to see what's going on, but all are valid.


    Good luck!
Sign In or Register to comment.