PDA

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



denwag
02-01-2007, 06:50 PM
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

Bruce Bates
02-01-2007, 09:10 PM
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

denwag
02-01-2007, 09:23 PM
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

denwag
02-02-2007, 10:05 PM
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 Bates
02-02-2007, 10:43 PM
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 -->