• AVR Freaks

Hot!Simple code not running in debugger

Author
JustRob
Super Member
  • Total Posts : 468
  • Reward points : 0
  • Joined: 2008/09/04 12:49:27
  • Location: 0
  • Status: offline
2020/01/16 11:08:54 (permalink)
0

Simple code not running in debugger

I designed a simple stepper motor drive circuit board.  I'm using the pic16lf18345 with the ICD3 and the latest versions of MPLab X and the XC8 compiler.
 
My circuit board powers up, connects to the ICD3 and programs the pic successfully.  I have very simple code (see insert).  I set a breakpoint just before the system_init funcion and the debugger breaks there but when I try to step forward and into the system_init function the program jumps to the closing brace of the while loop.  It does not execute the system_init function.  
 
It also will not allow me the place a breakpoint on the system_init function or on the first statement inside the system_init function.  Please see the code excerpt.
 
// CONFIG4
#pragma config CP = OFF // User NVM Program Memory Code Protection bit (User NVM code protection disabled)
#pragma config CPD = OFF // Data NVM Memory Code Protection bit (Data NVM code protection disabled)

// #pragma config statements should precede project file includes.
// Use project enums instead of #define for ON and OFF.

#include <xc.h>
#include "system-resources.h"
#include "allegro-stepper-ctrl.h"
//#include "spi-16lf.h"


void main(void) {
    
    OSCCON1bits.NOSC = 0b000; // Set internal oscillator 32MHz
    OSCCON1bits.NDIV = 0b0011; // Set oscillator divider to 8 for Fcy = 4MHz
    
    void system_init();
    //void test_x_stepper();
    //void test_y_stepper();
    
    
    while(1){
        
    }
}

 
I'm kind of at a loss as to why this isn't running.
#1

12 Replies Related Threads

    Jim Nickerson
    User 452
    • Total Posts : 6474
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Simple code not running in debugger 2020/01/16 11:12:55 (permalink)
    +2 (2)
    try changing "void system_init();" to "system_init();"
    #2
    du00000001
    Just Some Member
    • Total Posts : 3349
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Simple code not running in debugger 2020/01/16 11:13:01 (permalink)
    0
    Hi Rob,
     
    which version of XC8 / MPLAB X ?
     
    And do you mind to provide the code of system_init() ?

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #3
    du00000001
    Just Some Member
    • Total Posts : 3349
    • Reward points : 0
    • Joined: 2016/05/03 13:52:42
    • Location: Germany
    • Status: online
    Re: Simple code not running in debugger 2020/01/16 11:14:09 (permalink)
    +2 (2)
    wink  Jim saw the obvious

    PEBKAC / EBKAC / POBCAK / PICNIC (eventually see en.wikipedia.org)
    #4
    Jim Nickerson
    User 452
    • Total Posts : 6474
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Simple code not running in debugger 2020/01/16 11:15:18 (permalink)
    +1 (1)
    this presumes 

     
    void system_init(void)
     
    {
     
    Nop();
     
    }
     

    has been inserted before main calls it
     edit: I missed the void within the parens, thank you ric
    post edited by Jim Nickerson - 2020/01/16 12:58:24
    #5
    JustRob
    Super Member
    • Total Posts : 468
    • Reward points : 0
    • Joined: 2008/09/04 12:49:27
    • Location: 0
    • Status: offline
    Re: Simple code not running in debugger 2020/01/16 11:17:31 (permalink)
    0
    That did it!!!!!!  Those ugggggg mistakes.
     
    void system_init(){
        
        LATAbits.X_DIR_LATCH = RIGHT;
        LATAbits.X_STEP_LATCH = 0;
        LATCbits.X_RESETn_LATCH = 0;
        LATCbits.X_MS1_LATCH = 0;
        LATCbits.X_ENABLE_LATCH = 0;
        LATAbits.Y_DIR_LATCH = UP;
        LATCbits.Y_STEP_LATCH = 0;
        LATCbits.Y_RESETn_LATCH = 0;
        LATCbits.Y_MS1_LATCH = 0;
        LATBbits.Y_ENABLE_LATCH = 0;
        LATBbits.SPI_SCK_LATCH = 0;
        LATBbits.SPI_SDO_LATCH = 0;
        LATCbits.SPI_GYRO_CS_LATCH = 1;
        
        TRISAbits.X_DIR_TRIS = 0; // set as output
        TRISAbits.X_STEP_TRIS = 0; // set as output
        TRISCbits.X_RESETn_TRIS = 0; // set as output
        TRISCbits.X_MS1_TRIS = 0; // set as output
        TRISCbits.X_ENABLE_TRIS = 0; // set as output
        TRISAbits.Y_DIR_TRIS = 0; // set as output
        TRISCbits.Y_STEP_TRIS = 0; // set as output
        TRISCbits.Y_RESETn_TRIS = 0; // set as output
        TRISCbits.Y_MS1_TRIS = 0; // set as output
        TRISBbits.Y_ENABLE_TRIS = 0; // set as output
        TRISBbits.SPI_SCK_TRIS = 0; // set as output
        TRISBbits.SPI_SDO_TRIS = 0; // set as output
        TRISBbits.SPI_SDI_TRIS = 1; // set as output
        TRISCbits.SPI_GYRO_CS_TRIS = 0; // set as output


    }

     
     
     Thank you guys!
    #6
    Jim Nickerson
    User 452
    • Total Posts : 6474
    • Reward points : 0
    • Joined: 2003/11/07 12:35:10
    • Location: San Diego, CA
    • Status: offline
    Re: Simple code not running in debugger 2020/01/16 11:17:34 (permalink)
    +1 (1)
    du00000001
      Jim saw the obvious


    the keyword coloring caught my eye and "stood out"
    #7
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Simple code not running in debugger 2020/01/16 12:32:14 (permalink)
    +2 (2)
    This:
    void system_init(){
        
        LATAbits.X_DIR_LATCH = RIGHT;
        LATAbits.X_STEP_LATCH = 0;

    should start with
    void system_init(void){

     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #8
    JustRob
    Super Member
    • Total Posts : 468
    • Reward points : 0
    • Joined: 2008/09/04 12:49:27
    • Location: 0
    • Status: offline
    Re: Simple code not running in debugger 2020/01/17 11:21:51 (permalink)
    0
    I have that in the header file.
     
       
    void system_init(void);

     
    #9
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Simple code not running in debugger 2020/01/17 14:28:01 (permalink)
    +1 (1)
    JustRob
    I have that in the header file.
     
       
    void system_init(void);


    So why isn't your actual implementation of the function the same?
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #10
    JustRob
    Super Member
    • Total Posts : 468
    • Reward points : 0
    • Joined: 2008/09/04 12:49:27
    • Location: 0
    • Status: offline
    Re: Simple code not running in debugger 2020/01/17 14:59:45 (permalink)
    0
    I guess I've always done it like that and haven't run into a problem.  Is it a setup for a problem?  It's a simple fix.  I would like to be industry standard.
    #11
    ric
    Super Member
    • Total Posts : 25592
    • Reward points : 0
    • Joined: 2003/11/07 12:41:26
    • Location: Australia, Melbourne
    • Status: online
    Re: Simple code not running in debugger 2020/01/17 21:44:56 (permalink)
    +1 (1)
    Your declaration and your implementation should be an exact match.
    A function definition with no parameters can be interpreted as an "old style" definition by the C compiler.
    Avoid any dramas, and ALWAYS have a parameter list, even if it's just "void" for no parameters.
     
     

    I also post at: PicForum
    Links to useful PIC information: http://picforum.ric323.co...opic.php?f=59&t=15
    NEW USERS: Posting images, links and code - workaround for restrictions.
    To get a useful answer, always state which PIC you are using!
    #12
    JustRob
    Super Member
    • Total Posts : 468
    • Reward points : 0
    • Joined: 2008/09/04 12:49:27
    • Location: 0
    • Status: offline
    Re: Simple code not running in debugger 2020/01/17 22:11:18 (permalink)
    0
    Thanks Ric!
    #13
    Jump to:
    © 2020 APG vNext Commercial Version 4.5