set pins with shift and pin 13 for an ext. LED

All,

These seem like newbie questions that were probably answered before at some point but I searched and couldn't find anything.

  1. Is there a way to set all 14 output pins, or better yet a subset of them, via a bit string. Say I want to set all 14 HIGH. Can I somehow use a shift or some other command to write 11111111111111 and set them all high, or set pin 4-7 high with 00001111000000? Can I set every other pin high from pin 3-8 by using 101010 somehow? You get the idea.

  2. Is there a way to disable the on-board LED so I can use pin 13 to drive an external LED?

Thanks as always. The arduino is so cool, I have to ration my time w/it so I can function at work :slight_smile:

Hey libhart,

Take a look at the tutorial I wrote, in the section called "A word about port registers in the Atmega8 microcontroller":

http://www.arduino.cc/playground/Code/BitMath#registers

That's beautiful! Exactly what I wanted to do. Good points about the code not being portable though, I'll have to give it some thought. In my case I've got to set a sequence of pins high or low and I think it'd almost be more understandable w/the bit string than to have multiple 'for' loops all in a row. Thanks again.

Glad I double checked things on your tutorial. Told me how to do what I wanted, but the example is a bit off. In your setup function, you have the below. The top two lines are correct, but then the bottom two lines are switched. PORTB is 8-13, not 2-7, same switch for PORTD. Thanks.

// set pins 0 (serial transmit) and 2..7 as output,
// but leave pin 1 (serial receive) as input
// (otherwise serial port will stop working!) ...
DDRD = B11111101; // digital pins 7,6,5,4,3,2,1,0

// set pins 8..13 as output...
DDRB = B00111111; // digital pins -,-,13,12,11,10,9,8

// Turn off digital output pins 2..7 ...
PORTB &= B00000011; // turns off 2..7, but leaves pins 0 and 1 alone

// Write simultaneously to pins 8..13...
PORTD = B00111000; // turns on 13,12,11; turns off 10,9,8