Electrical – How to disable a microcontroller port once enabled

microcontrollermsp430pic

I'm using MP430 series microcontroller. The functionality of the code is to do a specific task and then don't do anything (sense the tilt and glow an LED in a fixed amount of time). But due to some bug in the code, I'm noticing that a port pin gets '1' after some time.
So now I want to disable all the ports once the task is completed. How can I disable these ports which initially I defined as Input and Output ports.

And my 2nd question is: if I'm disabling these ports then are there any chances that the output port (now disabled) will stay floating and generate some noise or something and trigger my output LED? This question is for all the microcontrollers (MSP430, PIC, AVR, etc.)

Best Answer

Pretty much every microcontroller will have it's ports' default state as 'input'. So just set the ports as inputs and you should be all set. One potential gotcha is if the pin has an internal pull-up or pull-down set, which could cause some issues, depending on your circuit. Lastly, most datasheets provide the default state of the bits in a given register. So to get the register back to how they were after the chip powered on, simply set the bits to their default state.