Cross Linking Functions.

(instructions, reset, WDT, specifications...) PIC17Cxx, PIC18Fxxx

Re: Cross Linking Functions.

Postby SLTom992 » Sat Jul 19, 2014 4:05 pm

That's fine with .h files but I still can't understand how to get the C files to recognize functions in the other file.

Code: Select all
void main () {

#include "display.c"
#include "main.h"

etc.

void display () {

#include "display.h"
#include "main.h"


I get the error message:
Display.h:1: error: (141) can't open include file "main.h": Too many open files

If I put the main.h information into the Display.h file and do not include main.h in either main or display I get the same message.

All of the references I've been able to discover on-line seem to be talking about GNU C and do it all with compile options.

I have four files - main.c and .h and display.c and .h - I'm about to put all of the information into the main.c and eliminate all the other files altogether.

Why should something that should be simple be so difficult?
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby Ian.M » Sat Jul 19, 2014 5:13 pm

It sounds like you may have inadvertently set up a recursive include chain. You are also probably not using include guards, or at least not using them properly. Package your whole project as a zip file (from within MPLAB) and attach it for us to look at and we can show you how to fix it.
Ian.M
Verified identity
 
Posts: 95
Joined: Wed May 28, 2014 12:47 am
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby SLTom992 » Sat Jul 19, 2014 7:22 pm

I did have a loop. I tried to follow the logic in that article recommended and included the .c files. That is what caused the loop. Now all is working. Now when my head heals from knocking it against the wall all will be well.
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby SLTom992 » Sun Jul 20, 2014 9:53 pm

OK, while the program now compiles without an error with the .h files included and the function prototypes included in the .h files it still does not operate:

Code: Select all
#define Set_Display_On_Off(char) (I have eliminated the .h file in this instance to simplify the problem)

void main () {
.
.
.
.
Set_Display_On_Off(1);
.
.
.



Results in the compile error:

Main.c:338: warning: (361) function declared implicit int

Which tells me that it doesn't understand the prototype. Anyone have any ideas of what is going on?
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby ric » Sun Jul 20, 2014 10:06 pm

Because "#define" is NOT a "prototype".
Change
#define Set_Display_On_Off(char)
to
void Set_Display_On_Off(char varname);

That is what should have been in the header file too.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Cross Linking Functions.

Postby SLTom992 » Sun Jul 20, 2014 11:10 pm

I tried that Ric and then when I call the function what I get during compile is:

main.c:339: error: (195) expression syntax
main.c:339: error: (312) ";" expected
main.c:339: error: (285) no identifier in declaration
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby ric » Sun Jul 20, 2014 11:17 pm

You've left out a semi-colon or a brace somewhere.
Could you post the whole file now?
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Cross Linking Functions.

Postby SLTom992 » Mon Jul 21, 2014 2:36 am

Code: Select all

#include <xc.h>
#include <stdlib.h>
//#include "Detector.h"

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

// CONFIG1H
#pragma config FOSC = XT        // Oscillator Selection bits (XT oscillator)
#pragma config PLLCFG = OFF     // 4X PLL Enable (Oscillator used directly)
#pragma config PRICLKEN = ON    // Primary clock enable bit (Primary clock is always enabled)
#pragma config FCMEN = OFF      // Fail-Safe Clock Monitor Enable bit (Fail-Safe Clock Monitor disabled)
#pragma config IESO = OFF       // Internal/External Oscillator Switchover bit (Oscillator Switchover mode disabled)

// CONFIG2L
#pragma config PWRTEN = OFF     // Power-up Timer Enable bit (Power up timer disabled)
#pragma config BOREN = SBORDIS  // Brown-out Reset Enable bits (Brown-out Reset enabled in hardware only (SBOREN is disabled))
#pragma config BORV = 190       // Brown Out Reset Voltage bits (VBOR set to 1.90 V nominal)

// CONFIG2H
#pragma config WDTEN = ON       // Watchdog Timer Enable bits (WDT is always enabled. SWDTEN bit has no effect)
#pragma config WDTPS = 32768    // Watchdog Timer Postscale Select bits (1:32768)

// CONFIG3H
#pragma config CCP2MX = PORTC1  // CCP2 MUX bit (CCP2 input/output is multiplexed with RC1)
#pragma config PBADEN = ON      // PORTB A/D Enable bit (PORTB<5:0> pins are configured as analog input channels on Reset)
#pragma config CCP3MX = PORTB5  // P3A/CCP3 Mux bit (P3A/CCP3 input/output is multiplexed with RB5)
#pragma config HFOFST = ON      // HFINTOSC Fast Start-up (HFINTOSC output and ready status are not delayed by the oscillator stable status)
#pragma config T3CMX = PORTC0   // Timer3 Clock input mux bit (T3CKI is on RC0)
#pragma config P2BMX = PORTD2   // ECCP2 B output mux bit (P2B is on RD2)
#pragma config MCLRE = EXTMCLR  // MCLR Pin Enable bit (MCLR pin enabled, RE3 input pin disabled)

// CONFIG4L
#pragma config STVREN = ON      // Stack Full/Underflow Reset Enable bit (Stack full/underflow will cause Reset)
#pragma config LVP = ON         // Single-Supply ICSP Enable bit (Single-Supply ICSP enabled if MCLRE is also 1)
#pragma config XINST = OFF      // Extended Instruction Set Enable bit (Instruction set extension and Indexed Addressing mode disabled (Legacy mode))

// CONFIG5L
#pragma config CP0 = OFF        // Code Protection Block 0 (Block 0 (000800-001FFFh) not code-protected)
#pragma config CP1 = OFF        // Code Protection Block 1 (Block 1 (002000-003FFFh) not code-protected)
#pragma config CP2 = OFF        // Code Protection Block 2 (Block 2 (004000-005FFFh) not code-protected)
#pragma config CP3 = OFF        // Code Protection Block 3 (Block 3 (006000-007FFFh) not code-protected)

// CONFIG5H
#pragma config CPB = OFF        // Boot Block Code Protection bit (Boot block (000000-0007FFh) not code-protected)
#pragma config CPD = OFF        // Data EEPROM Code Protection bit (Data EEPROM not code-protected)

// CONFIG6L
#pragma config WRT0 = OFF       // Write Protection Block 0 (Block 0 (000800-001FFFh) not write-protected)
#pragma config WRT1 = OFF       // Write Protection Block 1 (Block 1 (002000-003FFFh) not write-protected)
#pragma config WRT2 = OFF       // Write Protection Block 2 (Block 2 (004000-005FFFh) not write-protected)
#pragma config WRT3 = OFF       // Write Protection Block 3 (Block 3 (006000-007FFFh) not write-protected)

// CONFIG6H
#pragma config WRTC = OFF       // Configuration Register Write Protection bit (Configuration registers (300000-3000FFh) not write-protected)
#pragma config WRTB = OFF       // Boot Block Write Protection bit (Boot Block (000000-0007FFh) not write-protected)
#pragma config WRTD = OFF       // Data EEPROM Write Protection bit (Data EEPROM not write-protected)

// CONFIG7L
#pragma config EBTR0 = OFF      // Table Read Protection Block 0 (Block 0 (000800-001FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR1 = OFF      // Table Read Protection Block 1 (Block 1 (002000-003FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR2 = OFF      // Table Read Protection Block 2 (Block 2 (004000-005FFFh) not protected from table reads executed in other blocks)
#pragma config EBTR3 = OFF      // Table Read Protection Block 3 (Block 3 (006000-007FFFh) not protected from table reads executed in other blocks)

// CONFIG7H
#pragma config EBTRB = OFF      // Boot Block Table Read Protection bit (Boot Block (000000-0007FFh) not protected from table reads executed in other blocks)

// Prperties and definitions

// Definitions

#define LOW 0
#define HIGH 1
#define FALSE 0
#define TRUE 1
#define SLOW 0
#define FAST 1
#define TRUE_ON 1
#define TRUE_OFF 2
#define OUTPUT 0
#define INPUT 1
#define NO 0
#define YES 1
#define FALLING 0
#define RISING 1
#define OFF 0
#define ON 1
#define G0 1
#define DONE 0
#define HALF_SEC 500
#define ONE_SEC 1000


//------------------prototypes---------------------------------------------

int oled_12864(void);      // Display on = 1

// --------------------------Program -------------------------------------------

void main IO {
.
.
.
.
.
.
    oled_12864(void);



If I eliminate this call everything works normally. As soon as this function is called I get those error messages quoted above. I have inserted the entire main.h file with all of the functions as you suggest. Again it compiles without a complaint unless I make a call to any of the functions in the Display.c file.
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

Re: Cross Linking Functions.

Postby ric » Mon Jul 21, 2014 2:46 am

SLTom992 wrote:If I eliminate this call everything works normally.

If you eliminate WHICH call?

Your first error was in line #195, but you only supplied 110 lines.
Please, post the WHOLE file, or we are talking at cross purposes.
Latest test project, an LED matrix display made from one reel of addressable LEDs. here
User avatar
ric
Verified identity
 
Posts: 659
Joined: Sat May 24, 2014 2:35 pm
Location: Melbourne, Australia
PIC experience: Professional 5+ years with MCHP products

Re: Cross Linking Functions.

Postby SLTom992 » Mon Jul 21, 2014 3:53 am

Ric - The single CALL is to a function in the second "Display.c" file. Without that call everything compiles with no errors. Any call to the Display.c file causes the error. All of the calls that are contained within the main.c file compile and operate as expected.

I have shown you the prototype entered as you suggested. I tried that method initially and it gave me error messages so I attempted the "#define" method and the messages disappeared but the jump to the function wouldn't work. So you said that my original file was correct. I reconverted all of the subroutines in the main.h file to the original way and commented out the jump to the function in the Display.c file and it all compiled and operated properly. I uncomment the jump to the Display.c file and it will not compile.

Posting 15 functions that are working correctly until that specific function is called isn't going to accomplish anything is it? All I have to do is uncomment that call and it ceases to compile. Can you think of any manner in which that might occur other than a problem with the prototype functions?

The customer is a foreign country and does not want their code posted. So I am stuck showing you the problems and not the non-problems.
SLTom992
 
Posts: 58
Joined: Tue Jun 10, 2014 8:59 pm
PIC experience: Professional 1+ years with MCHP products

PreviousNext

Return to 16-Bit Core

Who is online

Users browsing this forum: No registered users and 4 guests

cron