Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

c18 pickit2 18f2525

Status
Not open for further replies.

breadboardguy

New Member
c18 pickit2 18f2525 problem, help needed!

I am trying to program a pic 18f2525 with c18 and a pickit2

But when i put the pic in the breadboard, no led lights up as in the "hello world" program gaved by microchip:

Is it because the 18f2525 only is in beta support with pickit2 ?

Thank you for your help in advance .

#include <p18f2525.h>
#include <delays.h>


#pragma config WDT = OFF //Disable watchdog timer

#define LEDPin LATBbits.LATB7 //Define LEDPin as PORT B Pin 7
#define LEDTris TRISBbits.TRISB7 //Define LEDTris as TRISB Pin 7

void main()
{
LEDTris = 0;//Set LED Pin data direction to OUTPUT
LEDPin = 1;//Set LED Pin

while(1)
{
LEDPin = ~LEDPin;//Toggle LED Pin
Delay10KTCYx(25);//Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles)
}

}


Programming Target (2010-06-18 14:48:33)
Erasing Target
Programming Program Memory (0x0 - 0x13F)
Verifying Program Memory (0x0 - 0x13F)
Programming Configuration Memory
Verifying Configuration Memory
PICkit 2 Ready

----------------------------------------------------------------------
Release build of project `C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.mcp' started.
Fri Jun 18 14:48:19 2010
----------------------------------------------------------------------
Clean: Deleting intermediary and output files.
Clean: Deleted file "C:\Documents and Settings\Yannick\Mes documents\Workspace\main.o".
Clean: Deleted file "C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.cof".
Clean: Deleted file "C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.hex".
Clean: Deleted file "C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.map".
Clean: Done.
Executing: "C:\MCC18\bin\mcc18.exe" -p=18F2525 /i"C:\MCC18\h" "C:\MCC18\example\getting_started\program3\main.c" -fo="main.o" -Ou- -Ot- -Ob- -Op- -Or- -Od- -Opa-
Executing: "C:\MCC18\bin\mplink.exe" /p18F2525 /l"C:\MCC18\lib" /k"C:\MCC18\bin\LKR" "main.o" /u_CRUNTIME /z__MPLAB_BUILD=1 /m"fafa.map" /w /o"fafa.cof"
MPLINK 4.35, Linker
Copyright (c) 1998-2010 Microchip Technology Inc.
Errors : 0

MP2HEX 4.35, COFF to HEX File Converter
Copyright (c) 1998-2010 Microchip Technology Inc.
Errors : 0

Loaded C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.cof.
----------------------------------------------------------------------
Release build of project `C:\Documents and Settings\Yannick\Mes documents\Workspace\fafa.mcp' succeeded.
Fri Jun 18 14:48:20 2010
----------------------------------------------------------------------
BUILD SUCCEEDED
 
Last edited:
Are you seeing the voltage toggle with at meter on the pin?
 
I dont have any multimeter for the moment(it broked)
If there was a toggle, the led should light up but it does'nt at all...

What can be wrong?
The only thing that i want is to see that the microcontroller is "alive"
I encountered that problem back ago when i tried in assembler ... it worked fine for 16f but not the 18f
 
Last edited:
It looks like you moved the LED from RA7 to RB7. RB7 is used by the ICSP connection. This can be a problem.

Not quite sure if you are using MPLAB but if you are, once you move the LED away from RB6 and RB7 you should be able to single step your code.
 
Not quite sure if you are using MPLAB

Is'nt it is in the build box i posted?

once you move the LED away from RB6 and RB7 you should be able to single step your code.

What do you mean by moving the LED away?
The code was originally intented for portd but there are none on the 18f2525 (only a.b.c)

#include <p18cxxx.h>
#pragma config WDT = OFF
void main (void)
{
TRISB = 0;
/* Reset the LEDs */
PORTB = 0;
/* Light the LEDs */
PORTB = 0x5A;
while (1)
;
}

The 18f2525 is braindead when i try this code ... i dont get any error messages but it simply does'nt works


I really need some help please ...
 
Last edited:
Sorry I just got back from a trip and was a bit fried. Here are some more down to earth instruction. Not why but how.

Move the LED to pin RB0

Change the code to reflect that.
#define LEDPin LATBbits.LATB0 //Define LEDPin as PORTB Pin 0
#define LEDTris TRISBbits.TRISB0 //Define LEDTris as TRISB Pin 0

Then select your pickit2 as under debugger instead of programmer.
It should connect to the pickit2 and id the chip correctly.
If all is well you should be able to step, run and debug in general.
 
You aren't defining an oscillator. Try changing your config line to,
Code:
#pragma config WDT = OFF, OSC = INTIO67

Mike.
 
I have just tried and

I am able to enter debug mode a step in with the pickit2 but the 18f2525 won't light the led up ...

#include <p18f2525.h>
#include <delays.h>

#pragma config WDT = OFF //Disable watchdog timer
#pragma config OSC = INTIO67

#define LEDPin LATBbits.LATB0 //Define LEDPin as PORTB Pin 0
#define LEDTris TRISBbits.TRISB0 //Define LEDTris as TRISB Pin 0


void main()
{
LEDTris = 0;//Set LED Pin data direction to OUTPUT
LEDPin = 1;//Set LED Pin

while(1)
{
LEDPin = ~LEDPin;//Toggle LED Pin
Delay10KTCYx(25);//Delay 250K cycles (1 second at 1MHz since each instruction takes 4 cycles)
}

}

Maybe just an hint so i can investigate wtf does'nt works ...
 
Last edited:
Mike pointed out another problem. Unless you setup the OSC it will use the default which is so slow that the one second delay you defined will take minutes or hours instead of a second.

Another thing that comes to mind is that you could have the LED wired wrong. You must have either the annode (+) to VDD or the cathode (-) to VSS and the other end to RB0 via a resistor.

I have no idea regarding you experience level so please do not chew off my head.
 
Another thing that comes to mind is that you could have the LED wired wrong. You must have either the annode (+) to VDD or the cathode (-) to VSS and the other end to RB0 via a resistor.

No, it is wired correctly (when i plug the wire on the +5v the LED lights up)

I have no idea regarding you experience level so please do not chew off my head.


I have made a line follower and other robots in assembler with mplab, but it seems i cant program it in c on 18f2525 !
There is no way i would "chew your head off",you are already kind enough to help me out






Is'nt the osc set up in my code? I used the piece of code Mike posted
I just crashed MPLAB by removing the 18f2525 while being in debug mode ...

I think the problem might come form the internal crystal configuration ...
While in debug mode, the program works correctly (it loops at the while loop in the new program)
Any ideas?

#include <p18f2525.h>
#include <delays.h>

#pragma config WDT = OFF //Disable watchdog timer
#pragma config OSC = INTIO67

#define LEDPin LATBbits.LATB0 //Define LEDPin as PORTB Pin 0
#define LEDTris TRISBbits.TRISB0 //Define LEDTris as TRISB Pin 0


void main()
{
LEDTris = 0;//Set LED Pin data direction to OUTPUT
LEDPin = 1;//Set LED Pin

while(1)
{
LEDPin = 1;
}

}
 
Last edited:
Try,
1) Either set config PBADEN=OFF for digital output on multiplexed I/O's with a-d, or set ADCON1=0Fh
2) 0.1uf cap across Vdd and Vss
3) 1k - 10k pullup on MCLR pin or possibly set config MCLRE=OFF?
 
Last edited:
I have tried whay you just wrote without any good results ...

#pragma config WDT = OFF //Disable watchdog timer
#pragma config OSC = INTIO67
#pragma const config FCMENB = OFF //Fail Safe Clock Monitor Disabled
#pragma const config IESOB = OFF //Internal External Osc. Switch Disabled
#pragma config PWRT = OFF //Power Up Timer Disabled
#pragma const config BOR = BOHW //Brown Out Reset Enabled in HW, SBOREN disabled
#pragma const config BORV = 20 //Brown Out Voltage : 2.0V
#pragma config DEBUG = OFF //DEBUG Disabled
#pragma config LVP = OFF //Low Voltage Programming Disabled

Is this configuration ok?
 
I still do not fully understand what the problem is.

Try adding this line at the start of function main.
I already added that

The big problem is that i am able to program the 18f2525 to put a LED on but i the real world, nothing happens ...


#include <p18f2525.h>
#include <delays.h>





#pragma config WDT = OFF //Disable watchdog timer
#pragma config OSC = INTIO67
#pragma const config FCMENB = OFF //Fail Safe Clock Monitor Disabled
#pragma const config IESOB = OFF //Internal External Osc. Switch Disabled
#pragma config PWRT = OFF //Power Up Timer Disabled
#pragma const config BOR = BOHW //Brown Out Reset Enabled in HW, SBOREN disabled
#pragma const config BORV = 20 //Brown Out Voltage : 2.0V
#pragma config DEBUG = OFF //DEBUG Disabled
#pragma config LVP = OFF //Low Voltage Programming Disabled




void main()
{
ADCON1 = 0x0F; //Make all digital

TRISB = 0;//Set LED Pin data direction to OUTPUT





while(1)
{
LATB = 0xFF;
}

}

This would be the most important question: Is there anything wrong in this program ?
Using the "Watch" window in the debug mode, i have been able to see that during the while(1) loop, LATB= 0xFF and TRISB to be 0x00

BUT ... when i put the microcontroller in the breadboard with an LED and power supply to the chip, then nothing happens

? ? ?


I am sure i am missing something obvious ... but what?

May you note that the 18f2525 is in BETA mode with pickit2
 
Last edited:
I am sure there is something wrong but the program works on the simulator and I would expect it to work on the chip too. (EDIT: The one time that this is not true is in regard to have the OSC and clock setup correctly)

It is impossible to know exactly what you are doing in that there are many things that we take for granted. If I could look over you shoulder it might be easy to spot.

Often times a thread like this ends with a duh moment. Often things like having the LED on the wrong pin or in backwards. Not saying you have done these.

There are several ways to run a program.

1. Program chip via the Program>picKit2 and run with the ICSP attached

2. As above but without the ICSP connected. Requires pullup on VPP pin.

3. Program chip via the Debug>picKit2 and run/debug with ICSP attached.

What will not work is program the chip via Debug>picKit2 and then disconnecting the ICSP.

When you talk about what you tried we need to know more about how you did it including which of the above methods.
 
Last edited:
OK ...

First, it works now ...

The problem came by the fact that i didnt placed a resistor on the MCLR
I have always programmed my 16f628a without one and i never had any problems. Why so?
 
Just glad you have it working. Both 16 and 18s require the pullup to run and I have always had them there during programming so I can not tell you.

I was thinking that during programming the picKit2 managed VPP and the pullup should not have been needed. Hey but what do I know.
 
Last edited:
Thank you all for your help

But my troubles aren't over
For some reason, i now get the PK2Error009 even with the usb cable connected and power LED on ... i will try to figure this one out alone but i hope the pickit2 is not broken neither the usb ... or else it will be the second time for the usb port :)
 
Last edited:
I haven't got a 2525 but do have a 18F2620 which is the same except for more memory. I have it on a breadboard and the following code blinks an LED on B0.
Code:
#include <p18f2620.h>
#include <delays.h>

#pragma config WDT = OFF //Disable watchdog timer
#pragma config OSC = INTIO67
#pragma config LVP = OFF

#define LEDPin LATBbits.LATB0 //Define LEDPin as PORTB Pin 0
#define LEDTris TRISBbits.TRISB0 //Define LEDTris as TRISB Pin 0

void main(){
    OSCCON=0x70;    //8MHz
    LEDTris = 0;    //Set LED Pin data direction to OUTPUT  
    LEDPin = 1;     //Set LED Pin
    while(1){
        Delay10KTCYx(50);
        LEDPin = !LEDPin;
    }
}

BTW, when you're posting code you are using quote tags and so your code looses it's formatting. Either type
Code:
 before it and
after or use the code button in advanced. It looks like, **broken link removed**.

Edit, didn't realise there was a page two!! Doh.

Mike.
 
Last edited:
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top