Connect with us

Start up I/O lines of PIC micro

Discussion in 'Microcontrollers, Programming and IoT' started by Rajinder, Mar 31, 2018.

  1. Rajinder

    Rajinder

    397
    7
    Jan 30, 2016
    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
     
  2. Harald Kapp

    Harald Kapp Moderator Moderator

    9,131
    1,842
    Nov 17, 2011
    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.
     
  3. Rajinder

    Rajinder

    397
    7
    Jan 30, 2016
    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
     
  4. Minder

    Minder

    2,823
    585
    Apr 24, 2015
    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: Mar 31, 2018
  5. BobK

    BobK

    7,599
    1,641
    Jan 5, 2010
    LATA = 0xFF; // set port A outputs to high
    TRISA = 0; // set port A to output

    Bob
     
  6. Minder

    Minder

    2,823
    585
    Apr 24, 2015
    Or from the manual.
    M.

    upload_2018-3-31_13-4-13.png
     
Ask a Question
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.
Electronics Point Logo
Continue to site
Quote of the day

-