Go Down

Topic: Specifying pin as INPUT not necessary (Read 1 time) previous topic - next topic

James C4S

Same as digitalWrite.  Write a 1.

e.g.
PORTB = 1;
PORTD = 1;
Capacitor Expert By Day, Enginerd by night.  ||  Personal Blog: www.baldengineer.com  || Electronics Tutorials for Beginners:  www.addohms.com

robtillaart


Quote
what's the direct port manipulation to turn on the internal pullups so the pins don't float?

DDRD = B01111100;     // set pin 0,1,7 as input, pin 2,3,4,5,6 as output
PORTD = B10000011;   // set pullups high for the pins 0,1,7

or PORTD = ~DDRD;     // maybe even simpler ;)
Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Nick Gammon


Using 1.0, board set to Uno.

1:  BareMinimum (blank setup and loop): 466 bytes.
3:  Loop to set pins 2-13 as INPUT:  652 bytes.



Yes, but a fair test is not an empty sketch. Otherwise who cares how much memory it takes? Or what the pins are?

This sketch:

Code: [Select]
void setup()
{
}

void loop()
 {
 }


For me was 450 bytes.




And adding the pinModes certainly pushed it up:

Code: [Select]
void setup()
{
 for (int x=0; x< A5; x++)
   pinMode (x, INPUT);
}

void loop()
 {
 }


Now: 636 bytes.




But let's assume that we use pinMode somewhere in our sketch:

Code: [Select]
void setup()
{
}

void loop()
 {
 pinMode (5, OUTPUT);
 }


Now it's 624 bytes. So we only really "lost" 12 bytes.




We confirm that here:

Code: [Select]
void setup()
{
 for (int x=0; x< A5; x++)
   pinMode (x, INPUT);
}

void loop()
 {
 pinMode (5, OUTPUT);
 }


That was 644 bytes. Only 20 bytes more than not doing it.




So, you can set them to inputs if you want. That is, if you don't believe the datasheet. But if you don't believe the datasheet you are going to have trouble programming it anyway.

The only thing I have found inconsistent with the datasheet is that pin 13 seems to be left high (but input) which means the internal pull-ups are enabled. Perhaps the bootloader shouldn't do that.

(edit) This was with version 0022 of the IDE so the actual figures vary slightly from those above.

Go Up