MPLAB debugging question

Discussion in 'Embedded Systems and Microcontrollers' started by Vaughanabe13, Jul 13, 2010.

  1. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    How do you view the return value of a function while you are debugging? FWIW I am using MPLAB with the C18 compiler for C source code and a PICKit3 for programming/debugging. Here is an example - lets say I have this simple function:

    Code ( (Unknown Language)):
    1. int returnNumbers(void)
    2. {
    3.     int num1 = 10;
    4.     int num2 = 5;
    5.     return (num1-num2);
    6. }
    I know how to use the watch window to view the contents of variables, but is there any way to directly view the value that is being returned from the function? I know I could do this by creating a new variable and setting it equal to the result, and then use the watch window to get that value, but I don't want to have to restructure my code that way.
     
  2. wannaBinventor

    Member

    Apr 8, 2010
    179
    4
    I'm not familiar with C or the 18F series of micros but if I had to guess, I'd say take a peep at the W register in the watch window.
     
  3. AlexR

    Well-Known Member

    Jan 16, 2008
    735
    54
    To use a return value of a function you assign the return value to a variable as in the example below. To see the return value all you need to do is watch the value of the variable that gets assigned the function return value.
    In the example below you would watch the value of the variable "result".
    Code ( (Unknown Language)):
    1. int returnNumbers(void)
    2. {
    3.     int num1 = 10;
    4.     int num2 = 5;
    5.     return (num1-num2);
    6. }
    7.  
    8. main()
    9. {
    10.     int result;
    11.     result = returnNubers();
    12. }
    13.  
     
  4. Vaughanabe13

    Thread Starter Active Member

    May 4, 2009
    102
    5
    Ok, I'm actually using the function in the middle of an equation, which is why it was inconvenient to do it that way, but I suppose I will change it if that's the only way. I was just curious to find out if there was another way.
     
Loading...