How to start debugging with MPLAB

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
I have a pickit 3 and I work with PIC 8-bit MCU's like PIC16F877A

IDE : MPLABX
Compiler: XC8
Language : C

I follow the following steps to program PIC Microcontroller

Project -> Double click on project Name
Build -> Run

Does anybody know the steps to debug code with MPLAB?
 

spinnaker

Joined Oct 29, 2009
7,835
I have a pickit 3 and I work with PIC 8-bit MCU's like PIC16F877A

IDE : MPLABX
Compiler: XC8
Language : C

I follow the following steps to program PIC Microcontroller

Project -> Double click on project Name
Build -> Run


Does anybody know the steps to debug code with MPLAB?

In MPLABX, I would need to go out on a limb and take a wild guess that you should click on Debug

upload_2019-4-17_21-53-33.png
 

Attachments

Last edited:

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
there is debug option in MPLAB IDE

upload_2019-4-18_16-27-47.png

I can build and Run the code but I don't understand how to debug following example code ?

C:
// 'C' source line config statements

// CONFIG
#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)


#include <xc.h>

#define _XTAL_FREQ 20000000 //Specify the XTAL crystall FREQ

#define PIR RC0
#define Buzzer RB2

void main() //The main function
{
   TRISB=0X00; //Instruct the MCU that the PORTB pins are used as Output.
   TRISC=0Xff; //Instruct the MCU that the PORTB pins are used as Input.
   PORTB=0X00; //Make all output of RB3 LOW

   while(1) //Get into the Infinie While loop
  {
    if(PIR ==1)
    {
        Buzzer=1;
        __delay_ms(1000);   //Wait
    }
    else
    {
        Buzzer=0;
    }
}

}
 

spinnaker

Joined Oct 29, 2009
7,835
Debug main Project is disabled for some reason. Never seen that. Do you have a Pickit 2 or 3 connected? Is it a real tool or a clone?
 

AlbertHall

Joined Jun 4, 2014
9,647
There is no short answer to that question. There are so many things you can do.
However, if you click on the left margin of a line of your code a red blob will appear. This sets a breakpoint.
Now when you run your code in debug mode it will be stopped at your breakpoint and you can view and change RAM and SFRs.
 

spinnaker

Joined Oct 29, 2009
7,835
There is no short answer to that question. There are so many things you can do.
However, if you click on the left margin of a line of your code a red blob will appear. This sets a breakpoint.
Now when you run your code in debug mode it will be stopped at your breakpoint and you can view and change RAM and SFRs.
In other words:

RTFM
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
There is no short answer to that question. There are so many things you can do.
However, if you click on the left margin of a line of your code a red blob will appear. This sets a breakpoint.
Now when you run your code in debug mode it will be stopped at your breakpoint and you can view and change RAM and SFRs.
I was trying to set breakpoints can you tell me how to do it?

upload_2019-4-20_17-21-51.png
 

AlbertHall

Joined Jun 4, 2014
9,647
Your image shows a breakpoint set at line 21.
If you now run the code it will stop at that breakpoint.
Click the button immediately to the left of the blue MCC shield.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
Your image shows a breakpoint set at line 21.
If you now run the code it will stop at that breakpoint.
Click the button immediately to the left of the blue MCC shield.
But we set two breakpoints to find a problem in the code.

Can you attach a screenshot of debugging process?
 

spinnaker

Joined Oct 29, 2009
7,835
But we set two breakpoints to find a problem in the code.

Can you attach a screenshot of debugging process?
Why don't you read the manual? And there are bound to be tons of generic tutorials on the internet that show how to use a debugger. They all have the same concepts.
 

spinnaker

Joined Oct 29, 2009
7,835
Learning how to operate the debugger is very easy. All you need to do is follow the instructions in the manual of how to operate the various tools like breakpoints and watches.

You can find definitions of breakpoints, watches etc on the internet. They are common tools used by most every debugger.

Learning how to use those tools to help you troubleshoot your problem is an entirely different matter. I am not sure that can even be taught. It is just going to take experience.
 

Thread Starter

Fanfire174

Joined Mar 13, 2018
240
Start at section 4.17 of the MPLAB(X) user guide and follow that through.
AlbertHall

I followed user guide but I am using letest IDE and compiler There may be some problem

I followed this instruction

File -> New Project
Microchip Embedded -> Standalone Project
Next
Family -> Device -> PIC16F877A
Next
Hardware Tool -> Pickit3
Next
compiler tool chain -> XC8
Next
Project Name -> PIR
Finish

Click on project PIR
source file -> new-> main.c-> PIR.c
finish

save code

click on project -> Build
click on project -> Run
click on project -> debug

set break pont ctrl + F8

But variable value doesn't change during debug process
 

Ian Rogers

Joined Dec 12, 2012
762
The debug facilities on the pic16f877a are extremely minimal... There is no debug header available so you are limited with ICD ( in circuit debugging ) to 1 level, which is rubbish.. If I were you, I would debug on the simulator as much as possible... When I used pickit3 for debugging I only get two breakpoints and that was on a mid range... I since use Proteus.. Real time debugging in a simulator.. Or as near as damn it..

If you are going to use ICD, you will be better off with ICD2.. There is a reason pickit's are cheap...
 
Top