How Can I write each bit of a 8bit binary number to pins 0-7
denwag
Posts: 8
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
Do
For x = 0 to 255
x = x + 1
debug bin x , CR
Next
pause 300
LOOP
Regards
Dennis Waggoner
Comments
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
Regards
Dennis Waggoner
What does the percent sign do?
Regards
Dennis Waggoner
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 -->