MPLAB X IDE compiler problem for PIC16F877A

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
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:
Rich (BB code):
#include <htc.h>
#include <pic.h>

void main()
{
   TRISB.F7 = 0; //Makes RB7 a output pin

   do
   {
      PORTB.F7 = 1;   //Turns ON relay
      Delay_ms(1000); // 1000 mS delay
      PORTB.F7 = 0;   //Turns OFF realy
      Delay_ms(1000); //1000mS delay
   }while(1);
}
and after compilling this code i have the following errors:
Rich (BB code):
make -f nbproject/Makefile-default.mk SUBPROJECTS= .build-conf
make[1]: Entering directory `E:/PIC-Code/Relay-Test/Relay-test.X'
make  -f nbproject/Makefile-default.mk dist/default/production/Relay-test.X.production.hex
make[2]: Entering directory `E:/PIC-Code/Relay-Test/Relay-test.X'
"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 
Relay-Test.c:6: error: struct/union required
Relay-Test.c:10: error: struct/union required
Relay-Test.c:11: warning: function declared implicit int
Relay-Test.c:12: error: struct/union required
(908) exit status = 1
make[2]: *** [build/default/production/Relay-Test.p1] Error 1
make[1]: *** [.build-conf] Error 2
make: *** [.build-impl] Error 2
make[2]: Leaving directory `E:/PIC-Code/Relay-Test/Relay-test.X'
make[1]: Leaving directory `E:/PIC-Code/Relay-Test/Relay-test.X'

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
 

t06afre

Joined May 11, 2009
5,934
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 :)
 

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
Thank you for the link but after modifying the code like this:
Rich (BB code):
//#include <htc.h>
#include <xc.h>
#include <pic.h>
#define _XTAL_FREQ=6000000;

void DelayMs(float s)// only to 3 decimals
{
    int milli_Equiv,i,j;  // milli second equivalent integer
    milli_Equiv=1000*s;
    for(j=1;j<=milli_Equiv;j++)
    {
        DelayMs(1);
    }
}


void main()
{
   //TRISB.F7 = 0; //Makes RB7 a output pin
    TRISB7 = 0;

   do
   {
      //PORTB.F7 = 1;   //Turns ON relay
      RB7=1;
      //Delay_ms(1000); // 1000 mS delay
      DelayMs(1000);
      //PORTB.F7 = 0;   //Turns OFF realy
      RB7=1;
      //Delay_ms(1000); //1000mS delay
      DelayMs(1000);
   }while(1);
}
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
 

Attachments

Thread Starter

PY01A0080

Joined Mar 7, 2013
42
SORRY I MADE A MISTAKE
it's working now
the correct code is:
Rich (BB code):
//#include <htc.h>
#include <xc.h>
#include <pic.h>
#define _XTAL_FREQ=6000000;

void DelayMs(float s)// only to 3 decimals
{
    int milli_Equiv,i,j;  // milli second equivalent integer
    int milli_Equiv=1000*s;
    for(j=1;j<=milli_Equiv;j++);
}


void main()
{
   //TRISB.F7 = 0; //Makes RB7 a output pin
    TRISB7 = 0;

   do
   {
      //PORTB.F7 = 1;   //Turns ON relay
      RB7=1;
      //Delay_ms(1000); // 1000 mS delay
      DelayMs(1000);
      //PORTB.F7 = 0;   //Turns OFF realy
      RB7=1;
      //Delay_ms(1000); //1000mS delay
      DelayMs(1000);
   }while(1);
}
Thank you for your help t06afre
 

t06afre

Joined May 11, 2009
5,934
You had some flaws in your code. This should compile ok, but I have not compiled it
Rich (BB code):
//#include <htc.h>
#include <xc.h>
//#include <pic.h>
#define _XTAL_FREQ 6000000
void main()
{
    TRISB7 = 0;
   while(1)
   {
         RB7=1;
      __delay_ms(1000);
          RB7=0;
       __delay_ms(1000);
   }
}
 

mekik

Joined Apr 7, 2014
1
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.
 

tshuck

Joined Oct 18, 2012
3,534
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.
Please start a new thread and post what errors you are getting when posting said thread.
 
Top