cmicrocontrollerpicmicroc

microC build failure due to struct/union required


this is my main.c program and there was a build failure due to "struct/union required". I'm using pic 13f877a microcontroller. I'll be really greatful if anyone can tell me the reason for this build failure. also there was another warning saying "36.1 function declared implicit int". what does that mean too?

#include<htc.h>
    #define _XTAL_FREQ 4000000
    __CONFIG(0X3F39);

    void main(){
      int a;
      TRISB = 0b00010000;           //RB4 as Input PIN (ECHO)
      TRISC = 0b00000000;           //C as Output PINs (LED)
      T1CON = 0b00010000;           //Initialize Timer Module

      while(1){
        TMR1H = 0;                  //Sets the Initial Value of Timer
        TMR1L = 0;                  //Sets the Initial Value of Timer
        PORTC = 0b00000000;
        PORTB.F0 = 1;               //TRIGGER HIGH
        Delay_us(10);               //10uS Delay
        PORTB.F0 = 0;               //TRIGGER LOW

        while(!PORTB.F4){           
            T1CON.F0 = 1;
        }               
        while(PORTB.F4){            
            T1CON.F0 = 0;               
        }

        a = (TMR1L | (TMR1H<<8));   //Reads Timer Value
        a = a/58;                   //Converts Time to Distance
        a = a + 1;                  //Distance Calibration
        if(a>=2 && a<=400){
            //with in the range
            PORTC = 0b11111111;
        } else {
            //out of range
            PORTC = 0b00000000;
        }
        Delay_ms(400);
      }
    }

Build C:\Users\user\Desktop\SmartDustbin for device 16F877A
Using driver C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe

Make: The target "C:\Users\user\Desktop\main.p1" is out of date.
Executing: "C:\Program Files (x86)\HI-TECH Software\PICC\9.81\bin\picc.exe" --pass1 C:\Users\user\Desktop\main.c -q --chip=16F877A -P --runtime=default --opt=default -D__DEBUG=1 -g --asmlist "--errformat=Error   [%n] %f; %l.%c %s" "--msgformat=Advisory[%n] %s" "--warnformat=Warning [%n] %f; %l.%c %s" 
Error   [196] C:\Users\user\Desktop\main.c; 15.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 16.1 function declared implicit int
Error   [196] C:\Users\user\Desktop\main.c; 17.10 struct/union required
Error   [196] C:\Users\user\Desktop\main.c; 19.16 struct/union required
Error   [196] C:\Users\user\Desktop\main.c; 20.10 struct/union required
Error   [196] C:\Users\user\Desktop\main.c; 22.15 struct/union required
Error   [196] C:\Users\user\Desktop\main.c; 23.10 struct/union required
Warning [361] C:\Users\user\Desktop\main.c; 36.1 function declared implicit int

********** Build failed! **********

Solution

  • You claim to be using MicroC, but the command line in your build output clearly shows you're actually using HI-Tech C 9.81, which is outdated and replaced with Microchip's XC8. HI-Tech C does not allow access to single bits in SFR's asif they were struct members, like MicroC does. You can only access registers as a full byte and need to perform bit manipulation yourself. For example, the line:

     PORTB.F0 = 1;   
    

    Would need to become:

    PORTB |= (1 << 0);
    

    Which is the common way to set a single bit in C. It shifts a 1 bit to the required position and OR's it into the destination byte, not altering other bits. Google for bit manipulation in C if you don't yet understand this.

    The function declared implicit int errors stem from the fact that the functions delay_us and delay_ms are not declared. HI-tech C uses the macro's __delay_ms and __delay_us. In addition, you will need to define _XTAL_FREQ with your PIC's operating frequency in Hz prior to using the delay macro's.