Some pics allow the port to be in a disconnect mode but not sure about this PIC.
If not I think this could actually make things worse, the pin could float and be in an indeterminate state drawing more current. It is better to either make it an A/D if possible or an output low, so if the switch was pressed you don't current limit the port pin.
Adam.
AFAIK, the GPIO pins on the PIC10F20x chips are either inputs, that are isolated (tri-stated) from the GPIO register when the TRIS instruction writes a "1" to that bit, or they are outputs that are in a low-impedance state, whether sourcing current as logical "1" or sinking current as logical "0". So, if a GPIO pin is going to be used as an input, it should either be pulled up with the internal "weak" pull-ups or connected externally to an appropriate impedance to either pull it up or pull it down. In any case, as you noted, it should not just be left to hang in the breeze. You could use a high-value external pull-down to establish logic "0" with a normally-open switch connected to Vcc to assert a logic "1" level when it is pressed, or use a high-value external pull-up to establish logic "1" with a normally-open switch connected to ground (Vss) Either way, pull up or pull down, current increases when the switch is pressed.
Suppose you choose to pull down the input to logic "0" with a passive resistor, and allow the switch actuation to apply Vcc to assert a logic "1". If you derive Vcc for the switch from an output port set to logic "1" you can "disconnect the switch" just by changing the output port to logic "0". Pressing the switch will have no effect on the input or the current drawn by the PIC.
The same principle applies if the switch is connected between the input and ground (Vss), except now the pull-up resistor is connected to an output port. If the output port is "1" the pull-up behaves normally, pulling the input port to logic "1" until the switch is actuated to drive the input to logic "0". If the output port is "0" the input may be "pulled down" to logic "0" (depending on the value of the pull-up resistor) but it certainly isn't floating. In either case, you ignore the input when the output port is at logic "0" and no increase in current occurs when the switch is actuated.
For Jeff's flashlight, the push-button switch input to the PIC has to be pulled up externally though a resistor connected to an unused output port. Fortunately there is one available, GP2. Your PCB circuit board would have to be modified to include a 10 kΩ resistor chip and the traces to connect it between GP2 and GP1.
The problem is the user can press the switch at any time. If this occurs while the flashlight is on and the PIC is asleep, current draw skyrockets if the pull-up is connected to Vcc. Other than the solution offered above, I also contemplated using one of the pins of the comparator in the PIC10F206 as a high-impedance switch input, maybe with an external resistor high enough in value to limit the current burden when the switch is pressed to a micro-ampere or so. But even if that worked, I am reluctant to do so because it would mean the PIC10F200 would have to be replaced with a PIC10F206. I am stubborn enough to want to see if I can do this with the PIC10F200.
Adam, you have already upgraded to a saner configuration, the PIC10F320, and back in Dayton I have ten of the low-power versions, the PIC10LF320, to play with. I like that version because you can dial down the clock oscillator in software to lower current requirements, albeit sacrificing execution speed. Plus, it has a 4-channel, 10-bit A/D converter, not applicable to the flashlight project, but certainly nice to have for other projects requiring low-resolution analog signal processing. The only downside I see right now is the maximum Vcc is 4.0 V so I will have to be more careful with the power supply, lest I let out the magic smoke. Not a problem with Jeff's flashlight of course because his battery only produces 4.0 volts.
Since I have the prototype breadboard up and running, I might just try an external pull-up for the switch driven from GP2. I hate giving up the FOSC/4 "heart-beat" signal on GP2 that I can see on the oscilloscope to re-assure me the PIC is running. But now that I have sleep working, that mostly goes away... just a few dozen clock pulses appear when I press or release the switch. So I guess I can do without it. More on that later.
Below is a picture of the prototyping breadboard, to the left of the BK multimeter, with me pressing the switch to light the LED and showing the current, 1121.5 μA, drawn by the PIC, the LED, and the "weak" pull-up resistor. The PIC was actually in "sleep" mode when this picture was taken. The breadboard above the multimeter is used to hold a three-terminal 7805 voltage regulator in the top right corner; a "power on" LED in the lower right; three PIC10F206 chips in the SOT-23 package, soldered to DIP headers; and a PIC10F206 in a PDIP package. The breadboard is just a convenient "place holder" for the chips, all of which I thought were "DOA" a few weeks ago... until I finally figured out I had to turn the comparator off to use the I/O ports assigned by default to the comparator inputs. One of the SOT-23 chips may actually be dead as I distinctly remember smoke coming up from the breadboard on the left when I was using this in Dayton last April, rather than here in Virginia Beach.
Hop