Controlling multiple digital output pins at once.

Hello,

I want to use 16 digital pins to control a 16-bit Digital to Analog Converter (DAC). As far as I understand to send 16 digital output HIGH/LOW commands to any arbitrary pin, call it pinx (which spans from 1:16), then I would have to write:
digitalWrite(pinx, 1);
sixteen times to produce a HIGH output on all channels.
To me this doesn't seem very elegant. Is it possible to declare all of the pins at once? For example something of the form:
digitalWrite(value, 1);
where value is a 16bit integer (like value = 1000110110001101 for arguments sake). Perhaps using a Bit Mask could work, but I am not 100%. I haven't managed to get it to work myself.

Similarly, if it is possible to do the above, is it possible to do the reverse with a 16 bit Analog to Digital Converter (ADC)? In other words writing 16 digital inputs to a single 16bit integer.

Any advice, or help with this would be greatly appreciated.

Kensington

If you are using an Uno I don't think you will have the full 8 pins at your disposal on any of the I/O ports. On every port at least one pin has a special purpose.

If you need I/O ports with the full 8 pins available to you then you should use a Mega.

...R

If the objective is to control a 16-bit DAC and not necessarily to use sixteen outputs doing it you could use shiftout() to 'bit bang' a hardware SIPO register and pulse a line to present all sixteen outputs simultaneously.

Delta_G:
You can even put the shift register on the SPI pins and drive it with the SPI hardware way faster than bit-banging it or using shift-out.

Nice! That's on my experiments list.

Yes, use two 74HC595 type shift registers.

digitalWrite (latchPin, LOW); // D10
SPI.transfer (highByte (dataWord));
SPI.transfer (lowByte (dataWord));
digitalWrite (latchPin, HIGH); // outputs update on this rising edge.

D13/SCK goes to SRCLK
D11/MOSI goes to SER In of first shift register, QH' goes to SER In of next chip
D10/SS goes to RCLK
OE goes to Gnd
SRCLR goes to +5.
0.1uF cap from VCC pin to Gnd

I've daisychained 45 chips this way.
Default speed of 4 MHz and MSBFIRST work just fine, so all you need in setup() is SPI.begin();