# PORTx Arguments

I am curious to know whether it is possible to give more arguments to PORTx other then just 2^x (where x is an positive integer).Suppose i want to control all pins at the same time with each pins showing different action based on HIGH or LOW.For example,i give PORTB=B00120101 which sets the pin 8,10,12,13 HIGH but the Pin12(with '2') having different action compared to Pin 18,10,13 (with '1').I know that pin can be either 5V or 0V.What if i want three logic level at the same time on different pins.I can do this with each pin one at a time but cannot seem to figure out doing all at the same time.

No. When you use the PORTx register, you are directly accessing the register.

You could, of course, read the value of the register, determine your logic, then write the final value.

One thing to be aware when doing raw port i/o is that operation like

val = PORTx;
val &= ~new_bits_mask; // strip out old bits
val |= new_bits; // or in new bits
PORTx = val;

are not atomic.

so if something that modifies other port bits in that same port register does it at interrupt level like a servo or IR library, that sequence has the potential to corrupt the register. To avoid this you must mask interrupts around the operation using:

noInterupts();
// code to protect
interrupts();

http://arduino.cc/en/Reference/Interrupts

--- bill

Excellent point Bill.

For example,i give PORTB=B00120101

Since when is two a binary value?

@Paul

Since when is two a binary value?

sorry its my mistake,its not a binary number.I was trying to use three logic level inputs at the same time and gave a wrong example.Could not do it so instead changed my approach.

i give PORTB=B00120101 which sets the pin 8,10,12,13 HIGH

Umm no. Binary numbers have the digits 0 and 1 in them.

What if i want three logic level at the same time on different pins.

Well, you can't, really.

Some experiments were done in the early days using different voltage levels, but almost every computer in existence is based on binary digital logic, on or off, 1 or 0, 5V or 0 volts.....

The alternatives have been shown to be not very practical, although every few years someone proposes them again.

Maybe when optical computing or quantum computing or some other concept finally arrives, the idea will run again.