CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

Complier error with #include

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
Barney



Joined: 18 Oct 2004
Posts: 41
Location: Newark, CA

View user's profile Send private message

Complier error with #include
PostPosted: Wed Apr 20, 2005 12:19 am     Reply with quote

I am trying to use #include to make routines reusable and am having a complier error. My experience with compliers is that the pre-processor resolves all of the #xxx commands before handing the text to the complier. The CCS output seems to imply the included c files are complied seperately. This seems weird, the failing line is the struct declaration and the #device is in the initial included h file. Any info? The manual is rather cryptic and a simple test case I wrote does not have the problem. Compiler is Ver 3.212.

The main code is:

Code:
#include <16F88.h>
#device *=16
#fuses NOWDT, NOPROTECT, NOLVP, HS
#use delay(clock=20000000)
#use rs232(baud=9600, XMIT=PIN_B5, RCV=PIN_B2, PARITY=N, BITS=8, STREAM=COMM_1)

#define MAX 5
Int16 Registry_Map[MAX];
Int8  REG_Map[MAX * 2];
#locate REG_Map = Registry_Map

#include "modbus.c"

void main(){
    int i;

    for(i=0; i<MAX*2; i++)
       REG_Map[i] = 0;
    while(1) {
       delay_ms(10);
       COMM1_Service();      
       }
}


The included modbus.c file is long so I am showing the first 25 lines or so. The problem is with the struct declaration:
Code:

// MODBUS exception codes
#define Illegal_Function     1
#define Illegal_Data_Address 2
#define Illegal_Data_Value   3
#define Slave_Device_Failure 4
#define Acknowledge          5
#define slave_device_Busy    6
#define Negative_Acknoledge  7
#define Memory_Parity_Error  8

struct Comm_Port    // <==== LINE 16 PROBLEM LINE
{  Int1  Respond;                      //respond to command
   Int1  Initialized;                   //initialized
   Int1  Packet;                      //packet ready for processing
   Int8  Network_Address;                //address of slave
   Int8  CRClo_Index;
   Int8  CRChi_Index;
   Int8  Index;                      //ptr into buffer
   Int8  Start;                      //starting register number
   Int8  Finish;                      //last register number
   Int8  Quantity;                      //number of registers
   Int8  Buffer[MAX*2 + 5];             //data buffer, + 5 bytes for packet overhead
                                 //slave addr, cmd, # data bytes, CRC Lo, CRC Hi
};
struct Comm_Port COMM1;


The complier output is:
Code:
Executing: "C:\Program files\Picc\CCSC.exe" "WaterMonitor.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
      Memory usage:   ROM=14%      RAM=15% - 16%
      0 Errors,  4 Warnings.
Executing: "C:\Program files\Picc\CCSC.exe" "modbus.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 128 "C:\Documents and Settings\Barney\PIC-C\Water\modbus.c" Line 16(1,5): A #DEVICE required before this line
Halting build on first failure as requested.
BUILD FAILED: Tue Apr 19 22:59:39 2005
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 12:58 am     Reply with quote

In the Project window in MPLAB, you probably have both your main C
source file and the modbus.c file. Remove modbus.c from the list.
Then it should compile without the #device error.

If you want to see modbus.c listed in the Project Window, then
add it to the "Other Files" section.

I tested this with MPLAB vs. 7.10.
Mark



Joined: 07 Sep 2003
Posts: 2838
Location: Atlanta, GA

View user's profile Send private message Send e-mail

PostPosted: Wed Apr 20, 2005 6:10 am     Reply with quote

Quote:
you probably have both your main C
source file and the modbus.c file


you definitely have both your main C
source file and the modbus.c file Smile
Guest








PostPosted: Wed Apr 20, 2005 6:33 am     Reply with quote

test
Barney



Joined: 18 Oct 2004
Posts: 41
Location: Newark, CA

View user's profile Send private message

PostPosted: Wed Apr 20, 2005 1:12 pm     Reply with quote

You nailed it. I had modbus.c listed as a C file. I removed and no more errors. Thanks.

Barney
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group