MPLAB X IDE compiler problem for PIC16F877A

Discussion in 'Embedded Systems and Microcontrollers' started by PY01A0080, Jul 2, 2013.

  1. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Hello,

    i've just downloaded the new MPLAB X IDE from Microchip and i'm trying to compile the very simple C program.

    Here's the code:
    Code ( (Unknown Language)):
    1. #include <htc.h>
    2. #include <pic.h>
    3.  
    4. void main()
    5. {
    6.    TRISB.F7 = 0; //Makes RB7 a output pin
    7.  
    8.    do
    9.    {
    10.       PORTB.F7 = 1;   //Turns ON relay
    11.       Delay_ms(1000); // 1000 mS delay
    12.       PORTB.F7 = 0;   //Turns OFF realy
    13.       Delay_ms(1000); //1000mS delay
    14.    }while(1);
    15. }
    and after compilling this code i have the following errors:
    Code ( (Unknown Language)):
    1. make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
    2. make[1]: Entering directory `E:/PIC-Code/Relay-Test/Relay-test.X'
    3. make  -f nbproject/Makefile-default.mk dist/default/production/Relay-test.X.production.hex
    4. make[2]: Entering directory `E:/PIC-Code/Relay-Test/Relay-test.X'
    5. "C:\Program Files\Microchip\xc8\v1.12\bin\xc8.exe" --pass1  --chip=16F877A -Q -G --asmlist  --double=24 --float=24 --opt=default,+asm,-asmfile,+speed,-space,-debug --addrqual=ignore --mode=free -P -N255 --warn=0 --summary=default,-psect,-class,+mem,-hex,-file --output=default,-inhx032 --runtime=default,+clear,+init,-keep,-no_startup,+osccal,-resetbits,-download,-stackcall,+clib "--errformat=%%f:%%l: error: %%s" "--warnformat=%%f:%%l: warning: %%s" "--msgformat=%%f:%%l: advisory: %%s"  -obuild/default/production/Relay-Test.p1  Relay-Test.c
    6. Relay-Test.c:6: error: struct/union required
    7. Relay-Test.c:10: error: struct/union required
    8. Relay-Test.c:11: warning: function declared implicit int
    9. Relay-Test.c:12: error: struct/union required
    10. (908) exit status = 1
    11. make[2]: *** [build/default/production/Relay-Test.p1] Error 1
    12. make[1]: *** [.build-conf] Error 2
    13. make: *** [.build-impl] Error 2
    14. make[2]: Leaving directory `E:/PIC-Code/Relay-Test/Relay-test.X'
    15. make[1]: Leaving directory `E:/PIC-Code/Relay-Test/Relay-test.X'
    16.  
    17. BUILD FAILED (exit value 2, total time: 562ms)
    Can someone help me why i have these errors ?
    In the beginning i tried to put #include<pic16f877a.inc> and i have the same errors

    Thank you
     
  2. blueroomelectronics

    AAC Fanatic!

    Jul 22, 2007
    1,758
    98
    Does the complier support TRISB.F7 ? (what does that even mean?)

    XC8 uses TRISBbits.RB7 = 0;
     
  3. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    As a start replace #include <htc.h> with #include <xc.h>
    Use __DELAY_MS(1000) not Delay_ms(1000) And also use the correct
    #define _XTAL_FREQ=xxxxxxx
    Use RB7 not PORTB.F7
    Use TRISB7 not TRISB.F7
    You must also take care of the configuration bits so they fit your hardware setting setting
    Both XC8 and PICs can be hard on the beginner so do not give up :)
     
  4. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Thank you t06afre,
    where can i find the configuration bits for the hardware setting and XC8
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
  6. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    Thank you for the link but after modifying the code like this:
    Code ( (Unknown Language)):
    1. //#include <htc.h>
    2. #include <xc.h>
    3. #include <pic.h>
    4. #define _XTAL_FREQ=6000000;
    5.  
    6. void DelayMs(float s)// only to 3 decimals
    7. {
    8.     int milli_Equiv,i,j;  // milli second equivalent integer
    9.     milli_Equiv=1000*s;
    10.     for(j=1;j<=milli_Equiv;j++)
    11.     {
    12.         DelayMs(1);
    13.     }
    14. }
    15.  
    16.  
    17. void main()
    18. {
    19.    //TRISB.F7 = 0; //Makes RB7 a output pin
    20.     TRISB7 = 0;
    21.  
    22.    do
    23.    {
    24.       //PORTB.F7 = 1;   //Turns ON relay
    25.       RB7=1;
    26.       //Delay_ms(1000); // 1000 mS delay
    27.       DelayMs(1000);
    28.       //PORTB.F7 = 0;   //Turns OFF realy
    29.       RB7=1;
    30.       //Delay_ms(1000); //1000mS delay
    31.       DelayMs(1000);
    32.    }while(1);
    33. }
    when i Build the code i have the following error message:
    cgpic.exe has stopped working
    please see the attached file.

    Is there another to compile the c code for PIC16F877A
    i have the same problem when i use MPLAB V6.60

    Thank you
     
  7. PY01A0080

    Thread Starter Member

    Mar 7, 2013
    42
    3
    SORRY I MADE A MISTAKE
    it's working now
    the correct code is:
    Code ( (Unknown Language)):
    1. //#include <htc.h>
    2. #include <xc.h>
    3. #include <pic.h>
    4. #define _XTAL_FREQ=6000000;
    5.  
    6. void DelayMs(float s)// only to 3 decimals
    7. {
    8.     int milli_Equiv,i,j;  // milli second equivalent integer
    9.     int milli_Equiv=1000*s;
    10.     for(j=1;j<=milli_Equiv;j++);
    11. }
    12.  
    13.  
    14. void main()
    15. {
    16.    //TRISB.F7 = 0; //Makes RB7 a output pin
    17.     TRISB7 = 0;
    18.  
    19.    do
    20.    {
    21.       //PORTB.F7 = 1;   //Turns ON relay
    22.       RB7=1;
    23.       //Delay_ms(1000); // 1000 mS delay
    24.       DelayMs(1000);
    25.       //PORTB.F7 = 0;   //Turns OFF realy
    26.       RB7=1;
    27.       //Delay_ms(1000); //1000mS delay
    28.       DelayMs(1000);
    29.    }while(1);
    30. }
    Thank you for your help t06afre
     
  8. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    You had some flaws in your code. This should compile ok, but I have not compiled it
    Code ( (Unknown Language)):
    1. //#include <htc.h>
    2. #include <xc.h>
    3. //#include <pic.h>
    4. #define _XTAL_FREQ 6000000
    5. void main()
    6. {
    7.     TRISB7 = 0;
    8.    while(1)
    9.    {
    10.          RB7=1;
    11.       __delay_ms(1000);
    12.           RB7=0;
    13.        __delay_ms(1000);
    14.    }
    15. }
    16.  
    17.  
     
  9. mekik

    New Member

    Apr 7, 2014
    1
    0
    hi all, good day. above code does not work for me. i found all declaration using asm code in pic.h, pic16f877a.h, pic16f877a.inc. i do not know either if there is an issue with mplabx IDE and xc8 compiler or specific setting need to be done.

    project properties checked ok.

    any help is appreciated.

    thank you.
     
  10. tshuck

    Well-Known Member

    Oct 18, 2012
    3,531
    675
    Please start a new thread and post what errors you are getting when posting said thread.
     
Loading...