PIC program question

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 MOVWF TRISA MOVLW 0x00 MOVWF TRISB CLRF TRISC

CLRF PORTA CLRF PORTB CLRF PORTC CLRF PORTE

; CALL FIFTEENMS SETF PORTA SETF PORTB SETF PORTC

GOTO $

Reply to
Randy Day
Loading thread data ...

RB5 is also used for LVP Mode. Have you got LVP enabled in the config register?

Reply to
Pete

Fire away.

Snipped. The code isn't at issue.

Yes.

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 culprit.

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.

BAJ

Reply to
Byron A Jeff

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 register.

best regards

H
Reply to
feebo
[snip]

That's two replies about LVP. I'll definitely be looking that up in the docs.

I, um, er, don't have one. 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. :)

Thanks

Reply to
Randy Day
[snip]

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. ;)

Randy

Reply to
Randy Day

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

formatting link

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 voltage.

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 there.

Every PIC has them. It's important to learn about the config bits as they can cause strange operation when you misconfigure them.

BAJ

Reply to
Byron A Jeff

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.

BAJ

Reply to
Byron A Jeff

___

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.

Reply to
Charles Jean
[snip]

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

formatting link

[snip]

[snip]

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

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.

Reply to
Randy Day

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: ww1.microchip.com/downloads/en/DeviceDoc/C18_Config_Settings_51537f.pdf

Thanks again everyone!

Randy

Reply to
Randy Day

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.