Simple debugging question

Status
Not open for further replies.

chris414

New Member
I apologize in advance if I'm being an idiot, but would someone please put me out of my misery and tell me how to watch a variable while debugging in MPLAB?
All I'm trying to do is watch the value of an integer variable which should be changing as I change the voltage applied to a pin. I've copied part of the code in below incase it's relavent to my question (I want to know the value of "result"):

Code:
	while(1)
	{	
	
		OpenADC(ADC_FOSC_32 &
					ADC_RIGHT_JUST &
					ADC_12_TAD,
					ADC_CH0 &  
					ADC_INT_OFF &
                    ADC_REF_VDD_VSS, ADC_1ANA);
		ConvertADC();         // Start conversion
  		while( BusyADC() );   // Wait for completion
		result = ReadADC();   // Read result
  		CloseADC();           // Disable A/D converter
		
		
		
		if(result>50)
		{
			LEDPin = 1;
		}
		else
		{
			LEDPin = 0;
		}
	}

I am using a PIC18F2550 with a PICKit2, the MPLAB IDE and MPLAB C18 Lite compiler.
 
Last edited:
Hi,

Build your project and open Debugger, before Runnning the code goto the View menu and open the File Registers (Down/restore that screen) and then you can also open a Watch Window where you can add in which system registers you may also want to see like ADRESL etc.

Once you have organised all those windows on your desktop, press f7 to single step through your code and watch the registers change.

If you have long delays etc, then use Breakpoints in your code, so you can F9 Run past the delay bit and then resume the single step.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…