Let's Make Robots!

Why is portc high = low?

Using Picaxe "portc", I can get 16 outputs from a picaxe 28, which is neat.

But I allways wondered why you have to write "high portc 5" to get "portc 5" to be "low"??

I understand that since it on default is an input-port, it must be set on "high" on power up. But still you should set it to "low" by writing "low portc 5", and not "high portc 5"?

Gets quite confusing sometimes in my code; half of the outs has to be set low to be high!?!?!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

Did you remember to do the

let dirsc = ...

and set the port to be output? Maybe that has something to do with it...

- Jimmy

Manual says:

Some microcontrollers allow inputs to be configured as inputs or outputs. In
these cases it is necessary to tell the microcontroller which pins to use as inputs
and/or outputs (all are configured as inputs on first power up). There are a
number of ways of doing this:
1) Use the input/output/reverse commands.
2) Use an output command (high, pulsout etc) that automatically configures the
pin as an output.
3) Use the let dirs = statement.

I go for "2)" - just use it as output.. But I have to set it to "low" to get it "high", and it is not only the initiating / first time, it is just how it is..

However - I am not quite sure I understand the "dirsc" - command.. Do you? Reading other peoples code, it will just accept a binary string (or a variable or number between 0-255 that it will read as 8-digit binary) - and the 8 digits will just tell which ports should be high / low.


.. And then the pins and pinsc.. well all just the same as "taking it one pin at a time" with High / low.. But still "high" / "low" comands are reversed on the portC's no matter what, as far as I can tell?


Dont we agree: "high portc 1" should turn portc 1 to output and make it high? Well try it. And then try to set it low..


/ Frits 

I have used "let dirsc = blah blah" on Picaxe Pete and it seems to work the way I wanted it... but then again I'm using a 40X1 chip...

Yes you understood dirsc right... it is a configuration of the direction of all the 8 pins in port c... I can't remember if 1 is output or input though (I think 1 is output). I prefer using the "let dirs / let dirsc" command when the directions don't change during execution.

- Jimmy

I have used it on a 28x1. The 1's in the dirsc command set the pin to output, 0's to input. So let dirsc=%00000001 sets pin 1 on port C as output and 2-8 as input. I haven't had problems with reversed high/low commands. What do you have attached to the pin?

.. OK - just to make sure, try to run this:



high portc 1

wait 4

low portc 1

wait 1

goto main


- and tell me then if the pin is low or high in 4 seconds?


/ Frits 

As expected, the pin went high on the high command and low on the low command. What do you have attached to the pin?

I can not believe this.

It has always been like that. Connected? anything!

I use the 28 pin project board, same for you?

/ Frits 

No I tested on my own home-made project board, but it should be the same.
I may have an answer. Tell me what type of PIC is embedded.

Erh - picaxe 28 :) Cant be bothered to look up what that is :) I'm cool thanks - I have learned that it is like that :)