Connect with us

PIC program question

Discussion in 'Electronic Basics' started by Randy Day, Aug 5, 2006.

Scroll to continue with content
  1. Randy Day

    Randy Day Guest

    I have a question for the PIC programmers among you.
    I'm programming a PIC18F2455, and I tried the code
    segment below to exercise the PIC and test the
    outputs with an LED.

    Pin RB5 on the chip does not go high. Before I label
    the chip as bad, is there any other register
    relating to RB5 that might need to be set/cleared?
    I notice in the docs that RB5 is part of an
    interrupt-on-change scheme, but AFAICT that should
    be off by default.

    Have I missed something, or is it just a blown micro?

    org 0
    ; Set up I/O ports
    MOVLW 0x00 ; Make Ports digital out
    MOVLW 0x00



    GOTO $
  2. Pete

    Pete Guest

    RB5 is also used for LVP Mode. Have you got LVP enabled in the config
  3. Byron A Jeff

    Byron A Jeff Guest

    Fire away.
    Snipped. The code isn't at issue.
    That's not it.
    You missed something. RB5 is the Low voltage programming pin.
    Unless you specifically used a high voltage programmer and
    disabled the LVP pin, it is completely out of the loop and
    unusable for any application specific purpose.

    What's your CONFIG line look like? It wasn't in your code.

    I suggest as a quick test to move the LED to another pin and
    to ground RB5. If everything works, then you've found your

    It's find of funny that with all of the I/O pins available on a
    40 pin part, you pick the pin that has a funky effect. But it's
    good to find because you now know that you must either disable
    LVP in your CONFIG statement or ground and not use RB5.

    Good luck.

  4. feebo

    feebo Guest

    Don't know about this specific device, but the TRIS registers are
    usually in a different bank to the actual port data registers. Can't
    see from this that you are switching banks to get to the tris
    registers. This code will definately not work on the PICs I have used.
    All bits are input by default and your TRISes are having no effect
    because you are not switching banks toget to the TRIS regs.

    If this is the case, have a look at the bank select bits in the status

    best regards

  5. Randy Day

    Randy Day Guest

    Byron A Jeff wrote:

    That's two replies about LVP. I'll definitely be
    looking that up in the docs.
    I, um, er, don't have one. </sheepish> I'm still
    fairly new with PIC's. I tried one from the examples
    in the programming kit on the 16F690, but the
    compiler choked on it when I ported stuff over to
    the '2455, so I left it out.

    I found this on the microchip forums:
    config LVP = OFF

    is that what I need, or is there more?

    If I disable LVP, will I be able to reprogram the
    device afterward? I'm using the PICkit 2; since it's
    USB-driven, I'm guessing it uses LVP.
    Everything else works without it grounded.
    I ran into a 'special function' pin arrangement
    learning on the '690, which is why I didn't
    automatically assume the device was bad.
    Actually it's the 28-pin SOIC version, and
    my project is using every one. I chose it by
    looking at the catalog listing and the pinout
    ('OK, it has 3 I/O ports, analog inputs, USB
    comm functions, and it's cheap').

    This was before I knew about things like config
    registers. :)
  6. Randy Day

    Randy Day Guest

    feebo wrote:

    No, this device is different. Harvard Architecture,
    I think they call it. The code above worked, it's
    just that one pin that didn't. Others have told me
    RB5 is used for low-voltage programming, and has
    to be configured.
    That's how it was on the learning micros I used, too. ;)

  7. Byron A Jeff

    Byron A Jeff Guest

    Usually folks find out about it when they get erratic operation.
    Understood. The 18F series has a completely different set of bits.
    And there's a ton of them. Here's a tiny url to an example posted
    in the Microchip forum

    Try cutting and pasting it and see how things go.
    Well that's a single line. As you can see from my link there's about
    10 lines of config bits to be set. And this set turns off LVP.
    More. Much more.
    Yes. The LVP bit cannot be disabled in LVP mode. So if you are using
    an LVP programmer, it cannot make the chip unprogrammable via LVP.
    It's HVP. There's a voltage booster circuit in the PK2 to get the high
    Then I'm not sure what's going on. If LVP is on I'd still ground the
    RB5 pin.
    Good chioce. USB is going to be the first 18F part I use when I get
    Every PIC has them. It's important to learn about the config bits as
    they can cause strange operation when you misconfigure them.

  8. Byron A Jeff

    Byron A Jeff Guest

    The 18F parts do not have the same banking issues as the 16F parts.
    Orthogonal issue that doesn't apply to this discussion.
    That's the problem here.

  9. Charles Jean

    Charles Jean Guest


    It would be helpful for the OP to check out the template files
    supplied by MPLAB. Kind of a "boiler-plate" asm file that includes
    everything required to make a dummy program. They are specific to
    each device and guaranteed to assemble and run. This way, important
    stuff like config statements would not be left out.
  10. Randy Day

    Randy Day Guest

    Byron A Jeff wrote:

    I found the following on MicroChip's forum as well:


    I disabled LVP. I now get a high on RB5,
    and a solid high on another pin that was

    Here's my config section now:
    #include <>
    config LVP = off
    config XINST = OFF
    config CPUDIV = OSC1_PLL2
    config WDT = OFF
    config DEBUG = OFF
    config PBADEN = OFF
    config LPT1OSC = OFF

    My next question is: what do I set to
    select a 24MHz internal clock, so that
    it's USB compatible?
    The USB portion is a future enhancement, but I
    wanted the functionality available.
  11. Randy Day

    Randy Day Guest

    I finally have correct output! Thanks to everybody who replied.

    I had one minor issue where pin RA6 was not config'd as output,
    but a quick scan of the docs showed me where I needed to look.

    The micro needs to be in ECIO or similar mode.

    For anyone who wants a list of the config codes available:

    Thanks again everyone!

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