Shop OBEX P1 Docs P2 Docs Learn Events
How Can I write each bit of a 8bit binary number to pins 0-7 — Parallax Forums

How Can I write each bit of a 8bit binary number to pins 0-7

denwagdenwag Posts: 8
edited 2007-02-02 14:43 in BASIC Stamp
Looking for a elegant way to count from 0-255 in binary and output x to pins 0-7.


Do
For x = 0 to 255
x = x + 1
debug bin x , CR
Next
pause 300
LOOP

Regards
Dennis Waggoner

Comments

  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-01 13:10
    Dennis -

    One should NEVER alter the iteration variable within a FOR ... NEXT loop. since all it will do is cause trouble. The program is nearly there with one deletion and one addition:

    Do
    ··· For x = 0 to 255
    ····· debug bin x , CR
    ····· OUTL = x
    ··· Next
    · pause 300
    LOOP

    Regards,

    Bruce Bates
  • denwagdenwag Posts: 8
    edited 2007-02-01 13:23
    Thank you very much with this infor I can begin to make my simple digital function generator. By outputing to my A/D Converter.

    Regards
    Dennis Waggoner
  • denwagdenwag Posts: 8
    edited 2007-02-02 14:05
    One this I did find is that I must specify DIRL=%11111111 inorder for OUTL to work

    What does the percent sign do?

    Regards
    Dennis Waggoner
  • Bruce BatesBruce Bates Posts: 3,045
    edited 2007-02-02 14:43
    Dennis -

    It indicates that you are specifying BINARY (only 0's and 1's) notation. PBASIC will accept DECIMAL, HEX and BINARY number notation. Unspecified is DECIMAL notation. A leading % sign, as noted, is BINARY notation. HEX notation is indicated by using a leading $ as in $AA.

    My apologies for not tossing in the appropriate DIRL command when I passed back the example to you. Certainly my error, and not yours.

    As you have now found out PBASIC needs to know the DIRection (input or output) of the pin ports, since all are potentially bi-directional. Many commands will automatically set the proper direction, just by the nature of the command.

    By way of example the commands HIGH and LOW will automatically set the specified pin port(s) to OUTPUT without the need for the DIRS command. You can also use the INPUT and OUTPUT commands to set individual pin ports in the proper direction.

    FWIW, upon start-up or on reset, all pin ports are automatically set to INPUT, so in reality one really only needs to set the appropriate OUTPUT pin ports. Also note the use of the PIN command, just for future reference. You MUST specify PBASIC 2.5 in a " '{$STAMP PBASIC 2.5} " directive in order for the PIN command to be functional.

    Regards,

    Bruce Bates

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    <!--StartFragment -->
Sign In or Register to comment.