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 CCS Technical Support

Compiling multiple source files

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



Joined: 25 Jan 2012
Posts: 13

View user's profile Send private message

Compiling multiple source files
PostPosted: Tue Apr 03, 2012 11:34 pm     Reply with quote

I need to split my source code in to pieces in order to maintain the simplicity but when compiling it gives number of errors.

Please somebody help me.
Code:

// main source file

#include <gps_main.h>
#include <Clock_functions.c>

#define Satalite_icon   0
#define Signal_level1   1
#define Signal_level2   2
#define Signal_level3   3
#define Signal_level4   4
#define Signal_level5   5
#define Hammer_icon     6
#define Clock_icon      7

#define RTC_SCLK PIN_A0
#define RTC_IO   PIN_A1
#define RTC_RST  PIN_A2
#include <DS1302.C>

#define LCD_DB4   PIN_C1
#define LCD_DB5   PIN_C2
#define LCD_DB6   PIN_C3
#define LCD_DB7   PIN_D0

#define LCD_RS    PIN_A7
#define LCD_RW    PIN_A6
#define LCD_E     PIN_C0
#include <flex_lcd.c>



//function decleration
void lcd_load_custom_chars(void);
void display_time();
void display_date();
void set_time();
//void set_date_year();
//void set_date_mth();
//void set_date_day();
//void set_date_dow();
//void clr_line2();
//void clr_line1();


//variable decleration
unsigned int  state=0,loop=0;
unsigned int  hr,min,sec;
volatile unsigned int  set_hr,set_min;
unsigned int  day,mth,year,dow,hour;
volatile unsigned int set_day,set_mth,set_year,set_dow;
const int c=0x20;
unsigned int backlit=0;

const int8 lcd_custom_chars[] =
{
// Char Number 0 -- Satalite_icon
0x07,0x15,0x0A,0x07,0x07,0x0A,0x15,0x07

// Char Number 1 -- Signal_level1
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x10

// Char Number 2 -- Signal_level2
 0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x18

// Char Number 3 -- Signal_level3
0x00,0x00,0x00,0x00,0x00,0x04,0x0C,0x1C

// Char Number 4 -- Signal_level4
0x00,0x00,0x00,0x00,0x02,0x06,0x0E,0x1E

// Char Number 5 -- Signal_level5
0x00,0x00,0x01,0x01,0x03,0x07,0x0F,0x1F

// Char Number 6 -- Hammer_icon
0x1C,0x1E,0x05,0x04,0x04,0x04,0x04,0x04

// Char Number 7 -- Clock_icon
0x00,0x0E,0x15,0x15,0x17,0x11,0x0E,0x00

};





//INT0 external interrupt
#int_EXT
void  EXT_isr(void)
{

}

//transmit buffer empty
#int_TBE
void  TBE_isr(void)
{

}

//recieve data awailable
#int_RDA
void  RDA_isr(void)
{

}

#int_TIMER1
void  TIMER1_isr(void)
{

}

#int_TIMER2
void  TIMER2_isr(void)
{

}

#int_TIMER0
void  TIMER0_isr(void)
{

}




void main()
{


setup_timer_0(RTCC_INTERNAL|RTCC_DIV_256|RTCC_8_bit);      //32.7 ms overflow
setup_timer_1(T1_INTERNAL|T1_DIV_BY_8);      //262 ms overflow
setup_timer_2(T2_DIV_BY_16,255,16);      //2.0 ms overflow, 32.7 ms interrupt
   setup_comparator(NC_NC_NC_NC);// This device COMP currently not supported by the PICWizard
   enable_interrupts(INT_EXT);
   enable_interrupts(INT_TBE);
   enable_interrupts(INT_RDA);
   enable_interrupts(INT_TIMER1);
   enable_interrupts(INT_TIMER2);
   enable_interrupts(INT_TIMER0);
   enable_interrupts(GLOBAL);
   setup_oscillator(OSC_8MHZ);
   
   rtc_init();
   lcd_init();
   delay_ms(500);
 

      while(true){
display_time();
display_date();

}
   

}//main loop ends


void display_time(){
lcd_load_custom_chars();
rtc_get_time(hr,min,sec) ;
lcd_gotoxy(0,1);
printf(lcd_putc,"TIME%02d:%02d:%02d"hr,min,sec);
printf(lcd_putc, "\f     \000F \n");
//printf(lcd_putc,"\000");
lcd_gotoxy(0,15);
lcd_putc(Satalite_icon);
}

void display_date(){
         rtc_get_date(day,mth,year,dow);
         lcd_gotoxy(1,2);
         if(dow==1)printf(lcd_putc," %02d-%02d-%02d   SUN" day,mth,year);
         if(dow==2)printf(lcd_putc," %02d-%02d-%02d   MON" day,mth,year);
         if(dow==3)printf(lcd_putc," %02d-%02d-%02d   TUE" day,mth,year);
         if(dow==4)printf(lcd_putc," %02d-%02d-%02d   WED" day,mth,year);
         if(dow==5)printf(lcd_putc," %02d-%02d-%02d   THU" day,mth,year);
         if(dow==6)printf(lcd_putc," %02d-%02d-%02d   FRI" day,mth,year);
         if(dow==7)printf(lcd_putc," %02d-%02d-%02d   SAT" day,mth,year);
         //delay_ms(200);
}

void lcd_load_custom_chars(void)
{
int8 i;

// Set address counter pointing to CGRAM address 0.
lcd_send_byte(0, 0x40); 

// Load custom lcd character data into CGRAM.
// It can only hold a maximum of 8 custom characters.
for(i = 0; i < sizeof(lcd_custom_chars); i++)
   {
    lcd_send_byte(1, lcd_custom_chars[i]);
   }

// Set address counter pointing back to the DDRAM.
lcd_send_byte(0, 0x80);
}

//clock functions file

#include <gps_main.h>

void set_time(){

delay_ms(1);
               rtc_get_time(hr,min,sec);
            lcd_gotoxy(0,1);
               printf(lcd_putc,"SET TIME   %02d:%02dn"hr,min);
            lcd_gotoxy(1,0);
            printf(lcd_putc," %15c" c);
               delay_ms(200);
             
               if(input_state(PIN_C6)==0){
               //beep();
               set_hr=hr;
               set_hr++;
               if(set_hr>23)set_hr=0;
               hour=set_hr;
               rtc_set_datetime(day,mth,year,dow,hour,min);
            backlit =0;
               }

                if(input_state(PIN_C7)==0){
                //beep();
                set_min = min;
                set_min++;
                if(set_min>59)set_min=0;
                min=set_min;
                rtc_set_datetime(day,mth,year,dow,hour,min);
            backlit =0;
                }

                if(input_state(PIN_D4)==0){
                //beep_twice();
                set_min = 0;
            min = set_min;
                set_hr = 0;
            hour = set_hr;
            rtc_set_datetime(day,mth,year,dow,hour,min);
            backlit =0;
                }
            backlit++;
         if(backlit==400){output_low(PIN_D6);}
            loop++;
            if(loop==2000)state = 0;
     
            if(input_state(PIN_D5)==0){
            delay_ms(20);
            //beep_twice();
         backlit =0;
            loop = 0;
            }

}

// error messages
Code:

Clean: Deleting intermediary and output files.
Clean: Deleted file "gps_main.ESYM".
Clean Warning: File "F:\GPS_software\gps_main.o" doesn't exist.
Clean: Deleted file "gps_main.ERR".
Clean: Done.
Executing: "E:\PICC\Ccsc.exe" +FM "gps_main.c" +EXPORT +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 23 "E:\PICC\devices\16F887.h" Line 2(8,9): Can not change device type this far into the code
*** Error 48 "E:\PICC\devices\16F887.h" Line 204(2,6): Expecting a (
*** Error 48 "E:\PICC\devices\16F887.h" Line 204(21,26): Expecting a (
*** Error 43 "E:\PICC\devices\16F887.h" Line 204(0,1): Expecting a declaration
*** Error 23 "F:\GPS_software\gps_main.h" Line 2(8,9): Can not change device type this far into the code
*** Error 48 "F:\GPS_software\gps_main.h" Line 2(9,12): Expecting a (
*** Error 43 "F:\GPS_software\gps_main.h" Line 2(0,1): Expecting a declaration
*** Error 23 "F:\GPS_software\gps_main.h" Line 3(8,9): Can not change device type this far into the code
*** Error 48 "F:\GPS_software\gps_main.h" Line 3(9,12): Expecting a (
*** Error 43 "F:\GPS_software\gps_main.h" Line 3(13,15): Expecting a declaration
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 6(28,29): Undefined identifier  -- rtc_get_time
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 7(14,15): Undefined identifier  -- lcd_gotoxy
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 8(23,31): Undefined identifier   lcd_putc
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 9(14,15): Undefined identifier  -- lcd_gotoxy
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 10(11,19): Undefined identifier   lcd_putc
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 15(16,22): Undefined identifier   set_hr
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 16(16,22): Undefined identifier   set_hr
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 17(19,25): Undefined identifier   set_hr
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 18(16,20): Undefined identifier   hour
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 19(32,33): Undefined identifier  -- rtc_set_datetime
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 20(12,19): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 25(25,32): Undefined identifier   set_min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 26(17,24): Undefined identifier   set_min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 27(20,27): Undefined identifier   set_min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 28(17,20): Undefined identifier   min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 29(33,34): Undefined identifier  -- rtc_set_datetime
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 30(9,16): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 35(25,32): Undefined identifier   set_min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 36(5,8): Undefined identifier   min
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 37(24,30): Undefined identifier   set_hr
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 38(6,10): Undefined identifier   hour
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 39(17,18): Undefined identifier  -- rtc_set_datetime
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 40(9,16): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 42(13,20): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 43(4,11): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 44(13,17): Undefined identifier   loop
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 45(16,20): Undefined identifier   loop
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 50(9,16): Undefined identifier   backlit
*** Error 12 "F:\GPS_software\Clock_functions.c" Line 51(18,22): Undefined identifier   loop
F:\GPS_software\gps_main.o ===>  39 Errors,  0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Wed Apr 04 11:01:37 2012

Please help to split the code.
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Wed Apr 04, 2012 2:31 am     Reply with quote

Some header files can only be loaded once in your project, for example the CCS PIC header files.
In your gps_main.h you do an include of 16F887.h and I suspect gps_main.h is included from all your C files? There it goes wrong because then the PIC header file will be loaded multiple times causing the error message for 'Can not change device type'.

The solution is to move the include of 16F887.h to the top of your main() C-file.

Another problem is that the file Clock_functions.c is using RTC functions but is included _before_ ds1302.c. Change the sequence of these two file includings.
jeremiah



Joined: 20 Jul 2010
Posts: 1346

View user's profile Send private message

PostPosted: Wed Apr 04, 2012 6:37 am     Reply with quote

Would the classical IFNDEF block fix that problem for him? I've not really had any good success with multiple file units on anything complex, so I just typically #include all my .c files at the end, but if he took his fuses and call to 16F887.h and put them in a header file like this:

device.h
Code:

#ifndef DEVICE_H
#define DEVICE_H

#include "16F887.h"

//Fuses here

#endif


would something like that work for him to avoid multiple #device calls interfering?
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