Maker Pro
Maker Pro

Start up I/O lines of PIC micro

Hi all,
I am writing some code for the PIC18F4520 micro..some of the code is to flash LEDs dependent upon certain conditions. I have set these I/O lines as outputs.
I am noticing that on switch on these LEDs are lit, sometimes randomly.
Should i make I/O lines as input initially to avoid this problem. Then configure as outputs after procesdor crystal and voltages are stable?
Thanks in advance
 

Harald Kapp

Moderator
Moderator
Typically a microcontroller's configurable I/O ports are input by default at startup. This avoids unwanted output by the micro during start up should these lines be used as inputs later. The drawback is that you need to ensure the correct level at these ports during startup. Usually a pull-up or pull down resistor of a few ten kΩ (e.g. 47.5 kΩ or 100 kΩ) should work - depending on your circuit. This resistor provides a know logic level (high or low) during startup until the ports have been programmed as output and set to the correct logic level.
 
Hi Harald
Thanks for your reply. I have these LEDs tied to 3V via resistors and the cathide of the LEDs going to the I/O lines. So a logic 0 will light the LED.
How can i make these as an input with the LEDs configured as above?
Thanks
 
Look at the manual for configure ports example code (A,B,C etc) for I/O.
Most pic's power up with I/O configured for analog enabled where applicable, see p105 in the manual for configure PORTA for example.
M.
 
Last edited:
Top