XOR, EOR aaaaargh

miniglub

New Member
I'm new to the PICAXE world and although I've no problem with most of the bits and pieces, I'm stuck on this one.

Anyone using the exclusive OR command in basic.
I'm playing aroung with a 293 motor driver and following some instructions from a book on inverting the directional control bits.
PICAXE 28X
code code code etc

high 1 ' to set forward direction
low 2

motor driver code etc.

pin1 = pin1 ^ 1 'to reverse direction
pin2 = pin2 ^ 1


Have tried simulator, no change in outputs 1 or 2 with EOR
Have tried a very basic programme to EOR outputs but still won't work


HELP please!!!!
 

BeanieBots

Moderator
Not too sure exactly what you are trying to do but you can't use "pin1" as both input and output at the same time.
Try this:-

b0=pin1
b0=b0 ^ 1
pin1=b0
 

hippy

Technical Support
Staff member
@ BeanieBots : Yes you can :)

It probably doesn't do what is desired, because it sets Output Pin 1 to the inverse of Input Pin 1.

Not sure about "outpin1 = outpin1 ^ 1" ... worth a try.
 

BeanieBots

Moderator
@ Hippy. On the same line? (pin1=pin1^1)
I would expect that to set output 1 to the inverse of input 1 which is what I understood WAS the desired effect.
Tried it in the simulator with unexpected results and (perhaps foolishly) assumed that is was due to the multiple assignment in one line causing the effect.
Not tried it on a real PICAXE.

b0=pin1
b0=b0 ^ 1
pin1=b0

gives the same result as I would expect from pin1=pin1^1
It also works in the simulator but again, not tried for real.

****************************
You're quite right hippy.
My PC must be as confused as me.
Just tried pin1=pin1 which worked fine.
tried pin1=pin1^1 and that worked fine too.
Now I'm bothered why I could have sworn it didn't work before

@miniglub
Maybe you should explain what you WANT it to do.
The lines of code do what I'd expect them to do.
 
Last edited:

miniglub

New Member
Thanks for coming back guys.

My aim is to enhance a rather static singing "Rudolph", and I'm doing a bit of testing prior to the final job.
One of my plans is to power a couple of small motors running forwards/backwards, and I copied some code from a book by David Lincoln as a starter.
It is this book that uses the pin = pin ^ 1 to invert the bits to the L293 driver and do the reversing.

Since posting I've had another look through the PICAXE manual 2 and can see that when using anything with pinx = pinx.. that this relates to (output)pinx = (input)pinx...

What confused me was that I was copying someone elses code which I assumed to be OK, as well as using output only pins.

In looking through the Basic guide in more detail, i've noticed the "toggle" command, which seems to do this inversion OK, also that the 28X1 chip supports a lot more commands that could be used. e.g. INVERT.

Would you recommend getting a 28X1 as I plan to do a bit of I2C stuff as well?

Thanks again

Oh for an easy life and a reindeer with a wagging tail!!
 

Tom2000

Senior Member
If you have no luck with the XOR function, try pinx = 1 - pinx. I don't know if it works in Picaxe syntax or not, but it flips a byte between 1 and 0. It might work for a pin, too.

Tom
 

hippy

Technical Support
Staff member
"pin1 = pin1 ^ 1" is an interesting bit of code; it behaves differnetly on different PICAXE's and differently under differing conditions.

On the PICAXE-18 upwards it reads an input pin, inverts and sets an output pin.

On the 08, 08M and 14M it does the same, but as the I/O are bi-directional, when the pin is an output, what is reads as input is what is put as output. In most cases anyway; if the loading is such that the pin is pulled high or low it will read that, rather than what is being put out.

TOGGLE is undoubtedly the easiest way to switch an output from high to low and vice versa, less confusing and will work on any PICAXE.
 

Tom2000

Senior Member
TOGGLE is undoubtedly the easiest way to switch an output from high to low and vice versa, less confusing and will work on any PICAXE.
Now *that* is downright embarrassing. I use toggle all the time, but never even thought of it in the context of this discussion. ARGGGHHHHH!!!!!!!!!!!!!!!!!!!!!

Tom
 
Top