I am facing an Issue with my PIC16f877A controller.

Its working in Debug mode with PicKit3 connected. But when I program the device for release mode, It gives no sign of working.

I am using MPLAB X with XC8 compiler

I have also connected 10k resistance between MCLR & VDD.

But still unable to resolve the issue.

Here is my main.c

#include "lib/System/config.h"
#include <xc.h>
#include <pic16f877a.h>
#include <stdio.h>
#include <stddef.h>
#include <stdlib.h>
#include <stdbool.h>
#include "lib/UART/UARTLib.h"
#include "lib/I2C/I2CInterface.h"
#include "lib/I2C/idmodule.h"

#pragma config FOSC = HS       // Oscillator Selection bits (HS oscillator)
#pragma config WDTE = OFF       // Watchdog Timer Enable bit (WDT disabled)
#pragma config PWRTE = OFF      // Power-up Timer Enable bit (PWRT disabled)
#pragma config BOREN = ON       // Brown-out Reset Enable bit (BOR enabled)
#pragma config LVP = OFF        // Low-Voltage (Single-Supply) In-Circuit Serial Programming Enable bit (RB3 is digital I/O, HV on MCLR must be used for programming)
#pragma config CPD = OFF        // Data EEPROM Memory Code Protection bit (Data EEPROM code protection off)
#pragma config WRT = OFF        // Flash Program Memory Write Enable bits (Write protection off; all program memory may be written to by EECON control)
#pragma config CP = OFF         // Flash Program Memory Code Protection bit (Code protection off)

static unsigned char data_Pkt_1[ MAX_BUF_SIZE ] = { NULL } ;                                // this is the buffer to accept incoming data
static unsigned char data_Pkt_2[ MAX_PKT_SIZE - MAX_BUF_SIZE ] = { NULL } ;             // this is the buffer to accept incoming data

bool isDataPktReceived = false;                         // Flag to check the incoming Data Pkt
bool opStatus = WRITE;

char start_byte_addr[] = { 0x00, 0x10, 0x20, 0x30, 0x40, 0x50, 0x60, 0x70 } ;
int maxBytes;
int Error = 0;

void receiveDataPkt();                                  // Function to receive Data from the PC
void transmitDataPkt();                                 // Function to transmit Data to the PC

void initIDComm();                                      // Function to Initialize ID Module Communication
void initBuffers();                                     // Initialize buffers with 0x00
void write_IDM( void );                                 // Function to Write ID Module
void read_IDM( void );                                  // Function to Read ID Module

bool validateData( void );                              // Function to Validate Data
void createResponsePkt( bool opStatus );                // Function to Create Response Pkt 
void createErrorPkt( void );                            // Function to create Error Pkt
void interrupt ISR(void);                               // Interrupt Service Routine

 Function : Main Function to Initialize the Operation
 Parameter : None
 Return   : None
int main()

    while (1)
        while ( idmCheckConnection() ) {
            if ( UART_GetRecvByteStatus() ) {
                UART_SetRecvByteStatus(false);              // Set Received flag False
                receiveDataPkt();                           // Receive Incoming data

            if ( isDataPktReceived ) {
                isDataPktReceived = false;
    return 0;

Please help me debugging the issue.

  • \$\begingroup\$ Did you compile/build it for "Release" rather than "Debug"? \$\endgroup\$ – Steve G Apr 28 '16 at 10:23
  • \$\begingroup\$ @SteveG, MPLABX has "Make & Program Device" option. Pressing this Icon, i guess, the Microcontroller should be programmed ?? \$\endgroup\$ – skg Apr 28 '16 at 10:31
  • \$\begingroup\$ I have not used MPLABX, only the original MPLAB which has a drop down box with the options Release and Debug, try to find something similar. But it is possible MPLABX works in a different way. \$\endgroup\$ – Steve G Apr 28 '16 at 10:46
  • \$\begingroup\$ Perhaps something like Target->Release? \$\endgroup\$ – Steve G Apr 28 '16 at 10:48
  • \$\begingroup\$ There is no such options like Release & Debug in MPLABX. \$\endgroup\$ – skg Apr 28 '16 at 10:49

According to this http://microchip.wikidot.com/mplabx:build-debug and http://microchip.wikidot.com/mplabx:build-release

MPLABX has separate build processes depending on whether you want to debug your target or run it freestanding. It appears that to run your target (freestanding) you just press Run Project. According to Microchip this will:

Builds (makes) the project in release mode, programs the target, and releases the device from reset so that the program starts running. The debug tool has no control over the program's execution in this mode.

  • \$\begingroup\$ I followed the steps mentioned in the link provided. But the issue remains the same. Somewhere I read that Crystal might be faulty. So, Does Crystal works while debugging using PicKit3 ???? \$\endgroup\$ – skg Apr 29 '16 at 8:06

It was a issue in Micro-controller. I changed the micro-controller & the issue got resolved.

But Still need to get answer, How does a Faulty micro-controller can work in Debug Mode. Well that would be a new thread.

  • \$\begingroup\$ Are you using an external oscillator? \$\endgroup\$ – slightlynybbled May 4 '16 at 4:31
  • \$\begingroup\$ @slightlynybbled, yes I am using 11.0592MHz Oscillator \$\endgroup\$ – skg May 4 '16 at 4:33
  • \$\begingroup\$ In my experience, if the oscillator circuit is marginal, then it will be flaky. Works with one, not with another. You might want to make adjustments to your oscillator and try your old microcontroller again so that your project will work with all microcontrollers. \$\endgroup\$ – slightlynybbled May 4 '16 at 4:37
  • \$\begingroup\$ @slightlynybbled, you might be right, But in that Case i have to change Oscillator to test the circuit. Also this would be rarest of rare issue. and the only solution would be to change Oscillator. \$\endgroup\$ – skg May 4 '16 at 5:07
  • 1
    \$\begingroup\$ Not so rare! These sorts of things happen all the time. No big deal if you are a hobbyist, but if you are moving things into production, you can have 10% scrap for no known reason. You are right, the only solution is to change the oscillator circuit. You don't have to change the oscillator value, but perhaps a different crystal or a small adjustment to your capacitors. In some cases, it just boils down to a better layout. Your call, not mine. \$\endgroup\$ – slightlynybbled May 4 '16 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.