need help with simple use of pic18f2455

Thread Starter

leviitzhak

Joined Apr 16, 2014
3
I am trying to use pic18f2455 and I could not manage to use it in a simple way.

I am new to pic programming and any helpful advice would be greatly appreciated.

Attached is the simplified schematic of my circuit.

I also attached the configuration file config.h that I am using. Its main parts being :

#pragma config FOSC = INTOSCIO_EC
#pragma config PWRT = OFF
#pragma config BOR = OFF
#pragma config WDT = OFF
#pragma config PBADEN = OFF
#pragma config MCLRE = ON
#pragma config STVREN = OFF

Now a simple program like the following would not light my LED :

#include<xc.h>
#include "config.h"

void main() {

TRISBbits.TRISB0 = 0;
LATBbits.LATB0 = 0;

for(int i=0; i<50; ++i){}

LATBbits.LATB0 = 1;
for( ; ; ){}

}

I managed to isolate the problem and I suspect a constant Power-on-Reset which I think I can show with the following code, which lets the LED constantly lit :

void main() {

TRISBbits.TRISB0 = 0;

if(RCONbits.POR == 0){
LATBbits.LATB0 = 1;
}else{
LATBbits.LATB0 = 0;
}

RCONbits.POR = 1;

for(int i=0; i<50; ++i){}

LATBbits.LATB0 = 0;
for( ; ; ){}

}

Any help will be appreciated. Thanks!!
 

Attachments

tshuck

Joined Oct 18, 2012
3,534
Yeah, this behavior is expected when switching Vdd and Vss. ;)

You may (probably) have killed it...

Did you program it out of circuit?

On the plus side, you remembered MCLR, which a lot of people forget...
 

Thread Starter

leviitzhak

Joined Apr 16, 2014
3
Thanks for your answer it helps me a lot.
Yes I programmed it out of circuit, probably switched once by mistake Vdd and Vss. It will take me a couple of days to get a new pic, is there a way to test if my pic is dead ?
 
Last edited:

THE_RB

Joined Feb 11, 2008
5,438
What is your power supply?

Many times a PIC can withstand reverse connection pretty well, it depends a lot on your PSU and how much current it can source.

Re testing the PIC, just try and use it.

You have a number of code errors. That PIC (from memory) needs to configure the ADC pins etc to make them digital or the port won't work as expected.

Then you have no while(1) loop to keep your code running, and you have no delay in there to slow down the flashing so your eye can see it.
:)
 

ErnieM

Joined Apr 24, 2011
8,377
One good test is to erase the PIC, program it, and verify the write.

A dead PIC cannot be programmed.

Meanwhile, this is a good time to try out the debugger, either the simulator built into MPLAB, or possibly thru your programmer to the hardware. PICkits can do that.
 

Thread Starter

leviitzhak

Joined Apr 16, 2014
3
Thanks THE_RB for your suggestions. I checked that I do supply 5V.

As for the code errors you are talking about, I have configured the only pin that I am using as being a digital I/O (port b). Why should I care about the rest ?

About the infinite loop, I did write a for( ; ; ), maybe you did not see it.

Thanks for your help, but I think tshuck got the problem at first sight : it is apparently because I switched Vdd and Vss.
 

ErnieM

Joined Apr 24, 2011
8,377
Hey RB, actually this should do what he thinks it should do... granted his code is horribly formatted to the point of obscurity. (That’s a hint leviitzhak ;-) )

The code checks if the power on reset flag is reset (normal after a power-on) and lights the LED, and after a time turns it off.

Whatever happens before the “LATBbits.LATB0 = 0;” should leave the LED off.

THEN an infinite loop is placed, so the code runs one and once only. That’s fine for a test.

leviitzhak: I do hope you powered BOTH Vss pins, and it wouldn't hurt to put the cap on the Vusb pin the spec calls for.
 

THE_RB

Joined Feb 11, 2008
5,438
Thanks Ernie, I only checked his text briefly and thought the goal was to flash a LED, and the code did not seem very good for that task... ;).
 
Top