Making all the port as output

Hay
I need to define the whole pot as output. Is there a way to do that without defining each port separately?
Thanks
Arbel

Hi Arbel,

You might want to be careful when setting all your pins to outputs because it can lead to accidental shorts.

You didn’t say what microcontroller you are using, so, since a lot of people around here use AVRs, I will tell you how to do it on the AVR. If you want to make port D all outputs you want to set all the bits in the D data direction register like this (in C):

DDRD = 0xFF;

If you need help with another microcontroller, you should post which one you are using and what language you are programming in.

- Ryan

I am using babyO Its atmega168. what do you meen shrtcuts? is I need to light up 7 leds at the same time (in a 7 segment number display) is there a problem doing that?
Arbel

When I said, “shorts,” I meant short circuits, not short cuts. On way short circuits can happen is when you accidentally connect a source output pin to a sink output pin. This creates a path from Vcc to GND that has very little resistance, meaning a high current will flow through the IO pins. The pins can not handle very much current (take a look at the atmega168 datasheet on Atmel’s website) and will probably break if they are part of a short circuit.

Using the Mega168’s IO pins to power 7 LEDs should be okay, as long as the LEDs have the right size resistor in series with them.

- Ryan

Hello.

I’d like to add that you do not need to set all the pins to outputs at the same time. You could do it one pin at a time and all the LEDs would seem to turn on simultaneously since it only takes a few hundred nanoseconds to execute an instruction on the Baby Orangutan.

- Ben