let dirs & let pins question

jims

Senior Member
Is there some way that I can use code with a combination of (highxx, let dirs and let pins) on the same bank of of the chip like this example code? With this code C.5 & C.7 will initially turn ON. However the first "let pins" command on C turns them OFF. I can't figure out if there is any way to make hi-bred code like this work. Am I "barking up the wrong tree"? Thank you, Jims
Code:
[color=Green]'***************************************************
'* Picaxe 20M2. Use "Let pins" to switch outputs.
'* NOTE: Must use "dirs" command first to set
'* pins to outputs. Pins set in "dirs" command
'* will be controlled by the "let pins" command.
'***************************************************[/color]

[color=Navy]#picaxe [/color][color=Black]20m2

init:
      [/color][color=Purple]dirsC [/color][color=DarkCyan]= [/color][color=Navy]%00011111  [/color][color=Green]'switch all C pins to outputs. 
      [/color][color=Blue]high C.5[/color][color=Black]: [/color][color=Blue]high C.7 [/color][color=Green]'Why are C.5 & C.7 reset by "pinsC" command????[/color]

[color=Black]main:
      [/color][color=Blue]do
       pause [/color][color=Navy]1000
       [/color][color=Purple]pinsC [/color][color=DarkCyan]= [/color][color=Navy]%0001 [/color][color=Green]; switch output 0 on
       [/color][color=Blue]pause [/color][color=Navy]1000
       [/color][color=Purple]pinsC[/color][color=DarkCyan]= [/color][color=Navy]%0000 [/color][color=Green]; switch all outputs off
       [/color][color=Blue]pause [/color][color=Navy]1000
       [/color][color=Blue]let [/color][color=Purple]pinsC [/color][color=DarkCyan]= [/color][color=Navy]%0011 [/color][color=Green]; switch outputs 0,1 on
       [/color][color=Blue]pause [/color][color=Navy]1000
       [/color][color=Purple]pinsC[/color][color=DarkCyan]= [/color][color=Navy]%00000000 [/color][color=Green]; switch all outputs off
       [/color][color=Blue]pause [/color][color=Navy]1000
       [/color][color=Blue]let [/color][color=Purple]pinsC [/color][color=DarkCyan]= [/color][color=Navy]%00000111 [/color][color=Green]; switch outputs 0,1,2 on
       [/color][color=Blue]pause [/color][color=Navy]1000 [/color][color=Green]; wait 1 second
      [/color][color=Blue]loop[/color]
 

Technical

Technical Support
Staff member
pinsC = %0001 ; switch output 0 on
pinsC = %00000001 ; switch output 0 on

are the same.

And as output C.5 and output C.7 are two bits on the left, the above will switch them off
Do this to keep them on:

pinsC = %10100001 ; switch output 0 on


 

jims

Senior Member
Thank you, technical... I really didn't ask the right question. I want to have C.5 & C.7 controlled only with "high & low" commands; while the other bits are controlled with the "pins" command. To have a split use of the C bank. Can this be done? Jims
 

BeanieBots

Moderator
It can be done but the 'best' way would depend on how/why/when you want control each bit.
One would be to set (only) the required bits in a byte (eg b0) and use "pins = b0"
Another method would be to use a mask to NOT alter C.7 & C.5 (eg OR with %10100000)
Maybe if you tell us why you want to control that way we can find a suitable method.
 

Hemi345

Senior Member
I get what Jims is asking...and I thought exactly the same thing but have never tested it.

But I guess the following is what really happens:
Using a dirsC = %00011111 command, will set C.0 thru C.4 as outputs and sets C.5 thru C.7 as inputs.

Then using High C.5, C.7 basically changes the dirsC command to include C.5 and C.7 for the PinsC command.
(changing the dirsC = %10111111)

So now a pinsC = %00000001 will actually turn off C.7 and C.5 in addition to C.4 thru C.1

I'd like to see an example of BeanieBot's OR method also as I just realized I'm going to be in the same predicament with my project (using C.0 thru C.3 to control a stepper motor while leaving C.4 thru C.7 alone) Thanks.
 

jims

Senior Member
(Hemi345) has explained it better than I did with this statement..."So now a pinsC = %00000001 will actually turn off C.7 and C.5 in addition to C.4 thru C.1". Is there any way around it? I actually want to use a servo command on the C.5 pin ( the "high C.5" was my attempt to quickly test this approach with thePE6 simulation before spending too much time on it). I'll set-up and test the servo idea soon as I get time. Jims
 

jinx

Senior Member
hi
servo command on pins C, have I missed something, thought servo's only worked on the B pins
 

hippy

Technical Support
Staff member
"So now a pinsC = %00000001 will actually turn off C.7 and C.5 in addition to C.4 thru C.1". Is there any way around it?
"Let pinsC=" will set all output pins on C to the level of the respective bits of the value they are being set to.

The best you can do is get the values of the pins as they are (outpinsC), and only alter the ones you want to adjust ...

Code:
dirsC = %10000001
Do
  High C.7
  pinsC = outpinsC |  %0000001 ; High C.0
  pinsC = outpinsC &/ %0000001 ; Low  C.0
  Low C.7
  pinsC = outpinsC |  %0000001 ; High C.0
  pinsC = outpinsC &/ %0000001 ; Low  C.0
Loop
 

jims

Senior Member
Thanks to all of you. A lot of good info. I caught the servo on C/B pins when tried to simulate in PE6. That editor sure tries to keep me honest. I have set this up using Picaxe VSM and found that I can use the "servo" command and the "readtemp" command with a DS18B20 on the B pins along with the the "let dirs & let pins". The VSM simulation runs as expected. Jims
 
Last edited:
Top