Can anyone help me with PIC18f4520 programming error?

olaf123

New Member

I am trying to run a program on PIC18F4520 using PicKit3 & MPLAB IDE. But I am getting an error: PK3Err0040: The target device is not ready for debugging. Please check your configuration bit settings and program the device before proceeding.

Whereas when I try to run one of the old program, its running. My new program code which is not running is:
B4X:
#pragma config OSC = HS,FCMEN = OFF,IESO = OFF              // CONFIG1H
#pragma config PWRT = OFF, BOREN = SBORDIS, BORV = 0                       // CONFIG2L
#pragma config WDT= OFF, WDTPS = 32768                                    // CONFIG2H
#pragma config MCLRE = OFF, LPT1OSC = OFF, PBADEN = ON, CCP2MX = PORTC       //CONFIG3H
#pragma config STVREN = ON, LVP = OFF, XINST = OFF                // CONFIG4L
#pragma config CP0 = OFF, CP1 = OFF, CP2 = OFF, CP3 = OFF                   // CONFIG5L
#pragma config CPB = OFF, CPD = OFF                                         // CONFIG5H
#pragma config WRT0 = OFF, WRT1 = OFF, WRT2 = OFF, WRT3 = OFF                // CONFIG6L
#pragma config WRTB = OFF, WRTC = OFF, WRTD = OFF                            // CONFIG6H
#pragma config EBTR0 = OFF, EBTR1 = OFF, EBTR2 = OFF, EBTR3 = OFF           // CONFIG7L
#pragma config EBTRB = ON                                                  // CONFIG7H


#include "p18f4520.h"
#include "delays.h"


void main(void)
{
TRISA=0b11111111;
TRISB=0b11111111;
TRISC=0b11111111;
TRISD=0b00000000;
TRISE=0x11111111;

while(1)
    {
     Delay10KTCYx(200);
     LATDbits.LATD3=1 ;
     LATDbits.LATD2=1 ;
     LATDbits.LATD1=1 ;
    }

}
Please let me know where the issue is? is it something to do with bootloader?
 

Toley

Active Member
Licensed User
Longtime User
First of all this is not the best forum to ask a microcontroller question. But If your PIC have a bootloader you cannot rewrite the config bits and debug it. And if you use a pickit3 to reprogram it, then you will erase the bootloader.
 

JordiCP

Expert
Licensed User
Longtime User
I believe you need to enable debugging in CONFIG4L (clear bit 7).
I would also try that. I have unzipped an old project which I made with the 18F26K22, using pickit3 and MPLAB, but CCS C compiler which has a different syntax for the fuses. Anyway, the DEBUG option was also set
B4X:
  #fuses INTRC_IO,DEBUG,NOPLLEN,PRIMARY,NOFCMEN,NOIESO,NOCPD,NOPUT,NOBROWNOUT,NOWDT,NOPROTECT,NOLVP,NOCPB,NOWRT,NOPBADEN,NOMCLR

Also, in your code...is this right?
B4X:
void main(void)
{
   TRISA=0b11111111;
   TRISB=0b11111111;
   TRISC=0b11111111;
   TRISD=0b00000000;
   TRISE=0x11111111; // <--------'x' ????? 
...
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…