Maker Pro
Maker Pro

Start up I/O lines of PIC micro

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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
Nov 17, 2011
13,719
Joined
Nov 17, 2011
Messages
13,719
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.
 

Rajinder

Jan 30, 2016
568
Joined
Jan 30, 2016
Messages
568
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
 

Minder

Apr 24, 2015
3,478
Joined
Apr 24, 2015
Messages
3,478
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:

BobK

Jan 5, 2010
7,682
Joined
Jan 5, 2010
Messages
7,682
LATA = 0xFF; // set port A outputs to high
TRISA = 0; // set port A to output

Bob
 
Top