setting pins with constants
mikea
Posts: 283
How can I assign a set of pins using binary with a letter...for ex: x=%1111 . To set pins 0-3 high. Thanks
Comments
The above would set pins 0, 1 and 2 as outputs.
If you also want the bit mask to be a constant you could do something like this:
The above would set pins 1 and 2 as outputs.
Edit: As with many programming tasks there are many ways to do this. A pin mask could be bitwise "or"ed to the dira register to set desired pins high.
now my head hurts...
-Tommy
As Mike stated your CON section needs to state " a = percent-sign111" <== Note to post readers: the web editor for the forum turns the percent sign and 2 following '1's to a null character...
But, the real error "may" be that you are not actually setting the outa register with your code: "outa[a]"...
Don't you need to do something like "outa[a]~" to set the pins low and "outa[a]~~" to set them high?
I get the following error in SimpleIDE when I try to compile your code:
So changed the code to:
which sets bits 0-2 to high...
I think we were all confused by the web editor's policy of reformatting the percent-sign characters when preceding the 1111's
dgately
My second example in post #2 sets both the pins used and the bit mask as constants. My verbose constant names could be changed to single letter names to better match mikea's original request. I didn't use single letter constants since I personally very much dislike single letter variable and constant names.
In general I try to make variable and constant names long enough a ctrl-f search will find only the name I'm looking for and not sections of other names.
BTW, The percent sign issue can be fixed by using switching to the "Basic Editor". From your profile select "Settings" (top right of screen), then select "General Settings" (under "My Settings"\"My Account" on the left side of the screen). Under "Miscellaneous Options" select "Basic Editor - A simple text box" ("Miscellaneous Options" is the last section of the "General Settings" page).
The Basic Editor can be a pain to use when you want to add pictures, links or video, so you may want to switch back to "Enhanced Interface - Full WYSIWYG Editing" after you've posted your code. The Basic Editor doesn't have the code "#" button in the advanced editor so you'll need to type out the code tags yourself.
Ah yes, it is a bit unclear what is needed versus what was asked.
Yes, variable names should have meaning and allow easy search...
Thanks for the info on the percent sign and using the basic editor, as I've had several posts that required special characters.
I generally type in the code tags anyway!
Thanks Duane!
dgately
How about making your outa statement a method?
Then whenever you type "A" you get the pins set the way you want.