Maker Pro
Maker Pro

PIC program question

R

Randy Day

Jan 1, 1970
0
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 $
 
P

Pete

Jan 1, 1970
0
Randy Day said:
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?



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

Byron A Jeff

Jan 1, 1970
0
I have a question for the PIC programmers among you.

Fire away.
I'm programming a PIC18F2455, and I tried the code
segment below to exercise the PIC and test the
outputs with an LED.

Snipped. The code isn't at issue.
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?
Yes.

I notice in the docs that RB5 is part of an
interrupt-on-change scheme, but AFAICT that should
be off by default.

That's not it.
Have I missed something, or is it just a blown micro?

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
 
F

feebo

Jan 1, 1970
0
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 $

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
 
R

Randy Day

Jan 1, 1970
0
Byron A Jeff wrote:

[snip]
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.

That's two replies about LVP. I'll definitely be
looking that up in the docs.
What's your CONFIG line look like? It wasn't in your code.

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

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

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. :)
Good luck.

Thanks
 
R

Randy Day

Jan 1, 1970
0
feebo wrote:

[snip]
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

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

That's how it was on the learning micros I used, too. ;)

Randy
 
B

Byron A Jeff

Jan 1, 1970
0
Byron A Jeff wrote:

[snip]
You missed something. RB5 is the Low voltage programming pin.
That's two replies about LVP. I'll definitely be
looking that up in the docs.

Usually folks find out about it when they get erratic operation.
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.

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

http://tinyurl.com/z74xw

Try cutting and pasting it and see how things go.
I found this on the microchip forums:
config LVP = OFF

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.
is that what I need, or is there more?

More. Much more.
If I disable LVP, will I be able to reprogram the
device afterward?

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.
I'm using the PICkit 2; since it's USB-driven, I'm guessing it uses LVP.

It's HVP. There's a voltage booster circuit in the PK2 to get the high
voltage.
Everything else works without it grounded.

Then I'm not sure what's going on. If LVP is on I'd still ground the
RB5 pin.
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').

Good chioce. USB is going to be the first 18F part I use when I get
there.
This was before I knew about things like config
registers. :)

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

BAJ
 
B

Byron A Jeff

Jan 1, 1970
0
feebo wrote:

[snip]
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

The 18F parts do not have the same banking issues as the 16F parts.
No, this device is different. Harvard Architecture,
I think they call it.

Orthogonal issue that doesn't apply to this discussion.
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 the problem here.

BAJ
 
C

Charles Jean

Jan 1, 1970
0
Byron A Jeff wrote:

[snip]
Have I missed something, or is it just a blown micro?
You missed something. RB5 is the Low voltage programming pin.
That's two replies about LVP. I'll definitely be
looking that up in the docs.

Usually folks find out about it when they get erratic operation.
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.

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

http://tinyurl.com/z74xw

Try cutting and pasting it and see how things go.
I found this on the microchip forums:
config LVP = OFF

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.
is that what I need, or is there more?

More. Much more.
If I disable LVP, will I be able to reprogram the
device afterward?

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.
I'm using the PICkit 2; since it's USB-driven, I'm guessing it uses LVP.

It's HVP. There's a voltage booster circuit in the PK2 to get the high
voltage.
Everything else works without it grounded.

Then I'm not sure what's going on. If LVP is on I'd still ground the
RB5 pin.
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').

Good chioce. USB is going to be the first 18F part I use when I get
there.
This was before I knew about things like config
registers. :)

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

BAJ
___

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

Randy Day

Jan 1, 1970
0
Byron A Jeff wrote:

[snip]
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

http://tinyurl.com/z74xw

I found the following on MicroChip's forum as well:
http://forum.microchip.com/tm.aspx?m=89669&mpage=15

[snip]
Then I'm not sure what's going on. If LVP is on I'd still ground the
RB5 pin.

[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 <p18F2455.inc>
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?
Good chioce. USB is going to be the first 18F part I use when I get
there.

The USB portion is a future enhancement, but I
wanted the functionality available.
 
R

Randy Day

Jan 1, 1970
0
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
 
Top