Access I/O pins as word, byte, nibble?

I am sort of migrating towards the Arduino from the Basic Stamp, and I am curious, is there any built-in way to address I/O pins in groups?

In other words, if I had four LEDs on pins 0-3 and I wanted to copy a BCD variable to those four pins, would I have to use digitalWrite(pin, value) four times, or is there a quick-n-dirty way to copy over a byte to four output pins? I know the scan time of the Arduino is relatively quick, and the human eye (or a 7447 perhaps) would not see the difference if each bit was written to in sequence instead of all at once, but it seems that one line of code beats four any day...

You can bypass the Arduino method and access each of the 8-bit ports by name, e.g. PORTD gets all 8 pins of port D, which happen to correspond to arduino pins 0-7. There are no nibble or word operations, although since we're talking about an 8 bit microcontroller one could argue that the 8 bit operations are word operations.

it seems that one line of code beats four any day...

Not if 4 lines are easier to write correctly or understand as compared to one line. I was taught once upon a time that above all the code should be correct and easy to understand. Worry about performance later, if you find there is a performance problem.

-j

Thanks and 73 Jason! I searched PORTD on the Aurduino site and was able to find out how to manipulate the I/O that way.

is there a quick-n-dirty way to copy over a byte to four output pins?

If you're going to be doing this in many places, it may be beneficial to write a function to handle it. The code below (untested, but it compiles) allows writing in nibbles.

//
// This function writes four bits of output simultaneously without
// modifying the remaining bits of a port.  Note that the four I/O
// pins must have previously been set to be outputs.
//
// The nibble number to port mapping matches the mega168-based
// Arduino boards.  Modifications may be needed for other hardware.
//
void digitalWriteNibble(byte nibNum, byte nibVal)
{
  byte sreg = SREG;
  cli();

  switch (nibNum)
  {
  case 0:  // pins 0-3, PORTD
    PORTD = (PORTD & 0xf0) | (nibVal & 0x0f);
    break;

  case 1:  // pins 4-7, PORTD
    PORTD = (PORTD & 0x0f) | (nibVal << 4);
    break;

  case 2:  // pins 0-3, PORTB
    PORTB = (PORTB & 0xf0) | (nibVal & 0x0f);
    break;
  }
  SREG = sreg;
}