What's the best way to set certain bits and tri-state remaining bits on SAME port????

OLDmarty

Senior Member
Hi All,

I need to set 2 bits of a port while also leaving the remaining 6 bits of the same port as Tri-state (set as inputs?)
Is there a preferred way to do this? and in what order?

I was first going to write a byte to the port, then set the port to input but i'm sure that erases my outputs that i just set to 1's or 0's.

While i can set the port as input (let dirsB = %00000000) should i then use "let pinsB = 00000011" to set just 2 bits on? or will this now force all the bits as outputs now?

My next thought was to FIRST make the port set as an input (all 8 bits), THEN individually 'set' any 2 (or more) bits to 1 or 0 as needed.
The 2 (or more) bits i need to set could be ANY of the 8 bits available.

I assume using 'set' is the best way to achieve this?
I feel that trying to 'and' the port with a number to isolate certain bits to be affected may over complicate the whole process.....maybe this is harder? easier?

Sorry, i can't try this myself, i'm moving house and my workshop/parts are packed in boxes. I only have a few chips at work to tinker with, so i now need to build a test jig to put some code together and try it out.


Anyone?

Thank in advance,
Marty.
 
Last edited:

oracacle

Senior Member
the way you do this may well depend on what you are trying to achieve.
When I built the Charlieplex clock I learnt that you can just
Code:
output {pin}
[/code

[code]
input {pin}
iirc using pinsb = may well affect operation if you forget to change things back to input after. aain from memory it not ideal not set the pins to ouput before using pinsb= command.
I think you should be able to use some sort of masking to deal with it, I will have a think but am sure that someone here will know strait away.

Edit:
Try using a bit wise and, don't forget that you can a variable in place of the binary, even with mathematics on the end

Code:
[color=Black]main:
      [/color][color=Blue]let [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]%00000011
      [/color][color=Blue]let [/color][color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Purple]b0 [/color][color=Black]| [/color][color=Navy]%10101011
      [/color][color=Blue]end[/color]
 
Last edited:

nick12ab

Senior Member
You will need to use let dirsB = %00000011. Pins are automatically set as outputs when using high / low / output commands, but not when using let pinsB.

Try using a bit wise and, don't forget that you can a variable in place of the binary, even with mathematics on the end

Code:
[color=Black]main:
      [/color][color=Blue]let [/color][color=Purple]b0 [/color][color=DarkCyan]= [/color][color=Navy]%00000011
      [/color][color=Blue]let [/color][color=Purple]dirsb [/color][color=DarkCyan]= [/color][color=Purple]b0 [/color][color=Black]| [/color][color=Navy]%10101011
      [/color][color=Blue]end[/color]
That example shows a bitwise OR, which will inadvertently set pins 7, 5 and 3 as outputs too.
 

oracacle

Senior Member
I knew I would get at least something wrong, however as an example to how the pins can be dynamically changed - which I what I got f(possibly incorrectly) rom the op - should at least get something going in the right direction
 

OLDmarty

Senior Member
Thanks guys, i'll tinker with your ideas above, albeit a few days away when i put together a proto board to play with ;-)

Oddly enough, the logic i'm needing closely resembles charlieplexing (i was just reading about it today and learning that it also requires Hi-Z states so other leds don't get falsely triggered.
Personally i've never built a charlieplex led array of any sort, although some of my own personal designs use the same/similar concept...a prallel invention maybe? I'll call it Martiplexing anyway lol

thanks again.
Marty
 
Top