View previous topic :: View next topic |
Author |
Message |
Guest
|
Multiple C files help |
Posted: Wed May 18, 2005 10:23 pm |
|
|
I am learning PIC Micro and C, I try to break my project files to more .c files.
When compile, it always get an error.
Clean: Deleting intermediary and output files.
Clean: Deleted file "light.$$$".
Clean: Deleted file "light.ERR".
Clean Warning: File "C:\PIC EXPERIMENT\light.o" doesn't exist.
Clean: Done.
Executing: "C:\PCM\PICC\Ccsc.exe" "light.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
*** Error 128 "C:\PIC EXPERIMENT\light.c" Line 4(1,1): A #DEVICE required before this line
Halting build on first failure as requested.
BUILD FAILED: Thu May 19 00:03:44 2005
Here is my files.
Code: |
// light.c file, will use this .c file as include file, the function of this file is to
// flash LED RD0 - RD7 in sequence with a delay of 10 ms.
light_left()
{
output_d(0x00);
output_high(pin_d0);
delay_ms(10);
output_low(pin_d0);
delay_ms(10);
output_d(0x00);
output_high(pin_d1);
delay_ms(10);
output_low(pin_d1);
delay_ms(10);
output_d(0x00);
output_high(pin_d2);
delay_ms(10);
output_low(pin_d2);
delay_ms(10);
output_d(0x00);
output_high(pin_d3);
delay_ms(10);
output_low(pin_d3);
delay_ms(10);
output_d(0x00);
output_high(pin_d4);
delay_ms(10);
output_low(pin_d4);
delay_ms(10);
output_d(0x00);
output_high(pin_d5);
delay_ms(10);
output_low(pin_d5);
delay_ms(10);
output_d(0x00);
output_high(pin_d6);
delay_ms(10);
output_low(pin_d6);
delay_ms(10);
output_d(0x00);
output_high(pin_d7);
delay_ms(10);
output_low(pin_d7);
delay_ms(10);
}
// Here is the main.c file
#include <16f877.h>
#fuses XT,NOWDT,PUT,NOPROTECT,NOLVP
#use delay(clock=4000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)
#include <light.c>
void button()
{
if(!input(pin_a4)) // if button RA4 pressed, light from RD0 - RD7, else light D1
{
light_left();
}
else
{
output_high(pin_d1);
}
}
main()
{
int value;
while(1)
{
button();
}
}
|
What is the right way to write a .c file that will be use as include file. Can
anybody take a look at my code and tell me what did I do wrong? I have
done search on linker in this forum PCM Programmer has posted alot of
instruction how to include the .c file, but I am new to c and PIC CCS, can
anybody help me out?
Thanks.... |
|
|
Guest
|
|
Posted: Wed May 18, 2005 10:34 pm |
|
|
Executing: "C:\PCM\PICC\Ccsc.exe" "light.c" +FM +DF +LN +T -A +M +Z +Y=9 +EA
you are compiling the light.c first you should be compiling the main.c |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
compiler message |
Posted: Thu May 19, 2005 5:50 am |
|
|
What does the compiler mean by this?
Clean Warning: File "C:\PIC EXPERIMENT\light.o" doesn't exist. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu May 19, 2005 6:15 am |
|
|
In addition to PCM's post, make sure that you are using the correct CCS tool suite. it is as "CCS C Compiler for PIC12/14/16/18". If you don't see it in the list then you need to download the CCS MPLAB plugin from CCS's website.
But to answer you question, it means that it couldn't find a file that it wanted to delete. This compiler doesn't generate .O files since it doesn't have a linker which is a clue that you are using the wrong tool suite which is the default one that MPLAB sticks in there. |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Thu May 19, 2005 11:42 am |
|
|
Firstly I am not the original poster, but having seen that somebody else gets the same warning message from the compiler as I do, I wanted to find out more. I only started to see this when I upgraded to MPLab ver 7.10.
Mark wrote: | But to answer you question, it means that it couldn't find a file that it wanted to delete. This compiler doesn't generate .O files since it doesn't have a linker which is a clue that you are using the wrong tool suite which is the default one that MPLAB sticks in there. |
I had thought about it being an intermediate .obj file - but as you say, CCS doesn't use a linker so I was puzzled.
Mark wrote: | In addition to PCM's post, make sure that you are using the correct CCS tool suite. it is as "CCS C Compiler for PIC12/14/16/18". If you don't see it in the list then you need to download the CCS MPLAB plugin from CCS's website. |
In my case I have checked that I have got the correct tool set - as its the only CCS toolset listed!. I was aware of previous posts that reported two versions listed. Yes I've got the plugin installed, along with MPLab v7.10 patch. As my code compiles correctly, I was assuming that it was an MPLab set up problem. |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Thu May 19, 2005 11:43 am |
|
|
damm double posted! |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Thu May 19, 2005 1:12 pm |
|
|
Quote: | I only started to see this when I upgraded to MPLab ver 7.10. |
I just did a test with MPLAB 7.10 and EX_LCDKB.C, and it worked
fine for me. The main file, EX_LCDKB.C, contains two include files,
as shown below. I didn't have any of the problems that you report.
Code: | #include <lcd.c>
#include <kbd.c> |
To do this test, fully install vs. 3.224 of the CCS compiler, along with the
CCS plug-in.
Then start MPLAB and go to the Project/Project Wizard menu.
The Wizard goes through 4 steps. Go through those steps
and follow the instructions for each one as shown below.
Step 1: Select 16F877 as the PIC.
Step 2: Select CCS C Compiler for PIC12/14/16/18.
Step 3: Type in EX_LCDKB as the Project name. For the project
directory, browse to c:\Program Files\Picc\Examples.
Step 4: Select the file EX_LCDKB.C and click the Add button.
You don't need to select the box to copy the file, because
the file is already in the project directory.
Then click the Finish button.
In the MPLAB project window (on the left side of the screen), you
should see this:
Code: | -.. C:\Program Files\PICC\Examples\EX_LCDKB.mcp
-..Source Files
.
......EX_LCDKB.C
.
..Header Files
.
..Other Files |
That's all you should see. There should be no other files shown in
the Source Files list. If there are, then remove them.
Now click the compile button on the toolbar, or go to the Project menu
and select Compile. It should compile without errors. You may get
a warning about "Condition always true." Ignore it.
After you compile, the Project window will now show 16F877.H in
the Header Files list.
If you're getting other results then you must be doing something
different than what is shown above. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Thu May 19, 2005 2:12 pm |
|
|
What is the description of the tool suite that you are selecting in MPLAB? |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Fri May 20, 2005 1:27 am |
|
|
Mark wrote: | What is the description of the tool suite that you are selecting in MPLAB? |
CCS C Compiler for PIC12/14/16/18
But I am running a rather old version of PCM v3.148 - but I dont think that's got anything to do with it. |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Tue May 24, 2005 11:32 am |
|
|
OK I am having MAJOR problems now with PCM hanging!
Time to rip everything out and do a complete reinstall of everything. Can someone advise what is the correct order of installation for PCM and MPLab 7.10. I intend to do it in the following order - is this correct?
1) install PCM
2) install plug-in
3) install MPLab 7.10
I think I read somewhere in the forum that I do not need the MPLab patch if using CCS - can some one please confirm. |
|
|
Mark
Joined: 07 Sep 2003 Posts: 2838 Location: Atlanta, GA
|
|
Posted: Tue May 24, 2005 12:36 pm |
|
|
I would do it in the reverse order of what you have. |
|
|
adrian
Joined: 08 Sep 2003 Posts: 92 Location: Glasgow, UK
|
|
Posted: Tue May 24, 2005 3:29 pm |
|
|
OK this is turning into a real saga.
First of all, I uninstalled all the relevant programs, and then went into the registery to clear out what the uninstall stuff left behind. I then went and did a fresh install of everything in the order listed above. But I still get the Clean Warning: File "C:\PIC EXPERIMENT\light.o" doesn't exist. May be I should have waited a bit longer for your reply Mark!
I also get a failed to load C:\PIC EXPERIMENT\light.COF. I saw the posting from Ian McCrum http://www.ccsinfo.com/forum/viewtopic.php?t=22414&highlight=mplab, but that solution has not helped. The only way I have found to avoid this message is to change the build option to no debug. This does not matter to me as I do not have a debugger anyway, but is there another way?
Finally, I solved the PCM hanging problem hurrah! I had cut and pasted a function - but forgot to include the closing brace. Shame on me. But this caused PCM v3.148 to hang. Closing the compile box then caused the MPLab output window to go berserk reporting the same fault over and over again pointing to the closing brace of main(). This effectively locked the program up.
So for something that was only going to take me half an hour to update, it has become a preverbial pain. |
|
|
anhtuan133
Joined: 04 Jul 2011 Posts: 1 Location: Việt Nam
|
CCS multiple files |
Posted: Mon Jul 04, 2011 1:56 am |
|
|
I think this is helpful for you. Using multiple files in MPLAB and CCS project.
Create a new project in MPLAB (toolsuite point to CCS) with name longer than 4 characters (bug!!!).
Create a.c, a.h, b.c ,b.h and reg.h. Add a.c and b.c to project tree
In reg.h:
Quote: |
#ifndef __REG_H__
#define __REG_H__
#include <16F886.h>
#device adc=10
#FUSES HS //xtal 4Mhz
#FUSES PUT //Power Up Timer
#FUSES MCLR //Master Clear as inout
#FUSES PROTECT //Code protected from reading
#FUSES NOCPD //No EE protection
#FUSES BROWNOUT //Reset when brownout detected
#FUSES NOIESO //No Internal External Switch Over mode enabled
#FUSES NOFCMEN //No Fail-safe clock monitor enabled
#FUSES NOLVP //No Low Voltage Programming on B3(PIC16) or B5(PIC18)
#FUSES NODEBUG //No Debug mode for ICD
#FUSES NOWRT //Program memory not write protected
#FUSES BORV40 //Brownout reset at 4V
//register define
#byte ANSELL = 0x188
#byte ANSELH = 0x189
#byte SSPCON = 0x14
#byte SSPCON2 = 0x91
#byte SSPADD = 0x93
#byte SSPSTAT = 0x94
#byte PORTA = 0x05
#byte TRISA = 0x85
#byte PORTB = 0x06
#byte TRISB = 0x86
#byte PORTC = 0x07
#byte TRISC = 0x87
#byte PORTE = 0x09
#byte TRISE = 0x89
#byte TXREG = 0x19
#byte RCREG = 0x1a
#byte TXSTA = 0x98
#byte BAUDCTL = 0x187
#byte RCSTA = 0x18
#byte SPBRG = 0x99
#byte SPBRGH = 0x9A
#byte INTCON = 0x0b
#byte PIE1 = 0x8C
#byte OPTION_REG = 0x81
//--CONFIG
#define F_CPU 4000000 //tan so clock
#define Fcy F_CPU
//========
#define ENABLE_GLOBAL_INTERRUPT() enable_interrupts(GLOBAL)
#define DISABLE_GLOBAL_INTERRUPT() disable_interrupts(GLOBAL)
#define NOP() delay_cycles( 1 )
#define RESET_WATCHDOG() restart_wdt()
#use delay(clock=F_CPU)
#endif
|
in a.c
Quote: |
#include "reg.h"
#include "a.h"
void main(void)
{
b_func();
}
|
in b.c
Quote: |
#include "reg.h"
#include "b.h"
void b_func(void)
{
}
|
in b.h
Quote: |
#ifndef __B_H_
#define __B_H_
void b_func(void);
#endif
|
It's work. |
|
|
|