View previous topic :: View next topic |
Author |
Message |
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
Error: A #DEVICE required before this line |
Posted: Sat Nov 20, 2004 5:31 am |
|
|
in main.c:
#include <led.h>
void main (void)
{
.....
led();
.....
}
in led.c
void led (void)
{
...
}
The declaration of the function led is in led.h
Where is my mistake in my code ? |
|
|
Will Reeve
Joined: 30 Oct 2003 Posts: 209 Location: Norfolk, England
|
|
Posted: Sat Nov 20, 2004 5:42 am |
|
|
You need to tell the compiler what PIC you are using via #device have a look at the example files. This is usually included in a .h file.
Will |
|
|
Ttelmah Guest
|
|
Posted: Sat Nov 20, 2004 5:45 am |
|
|
Where is your #device?.
#device is needed right at the start of the code, to define what processor to compile for. It can either be the first line of 'main', or can be the first line of the very first 'include' file. Without this, code will not compile.
Normally, most people #include the processor defintion file (so for a 16F84, #include <16F84.h>), as the first line of their code, which contains the #device command for the processor, and a lot of other useful (necessary in most cases) defintions.
Best Wishes |
|
|
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
|
Posted: Sat Nov 20, 2004 6:11 am |
|
|
I have the device include file in my main.c
#include <16F684.h>
#include <led.h>
void main (void)
{
.....
led();
.....
}
Sorry I´ve forgotten it in my Posting |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Sat Nov 20, 2004 6:18 am |
|
|
Do you have any other #include statements (or other C statements) before the #include <16F684.h> line by any chance? |
|
|
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
|
Posted: Sat Nov 20, 2004 6:32 am |
|
|
No, here´s my small test code:
main.c
#include <16F684.h>
#include <C:\Projekte\Sinus_Wechselrichter\Software\status_led.h>
void main(void);
void polling_mode(void);
void main(void)
{
polling_mode();
}
void polling_mode(void)
{
while(1)
{
led();
}
}
led.c
#include <C:\Projekte\Sinus_Wechselrichter\Software\status_led.h>
void led(void)
{
LED_ON;
LED_OFF;
}
led.h
#include <C:\Projekte\Sinus_Wechselrichter\Software\board.h>
#define LED_ON (output_high(STATUS_LED))
#define LED_OFF (output_low(STATUS_LED))
void led(void);
board.h
#define STATUS_LED PIN_A0
!!! Thank´s for help !!! |
|
|
asmallri
Joined: 12 Aug 2004 Posts: 1634 Location: Perth, Australia
|
|
Posted: Sat Nov 20, 2004 9:24 am |
|
|
status_led.h is being included in the main line and in led.c
also where do you actually include led.c? _________________ Regards, Andrew
http://www.brushelectronics.com/software
Home of Ethernet, SD card and Encrypted Serial Bootloaders for PICs!! |
|
|
Ttelmah Guest
|
|
Posted: Sat Nov 20, 2004 11:05 am |
|
|
How is 'LED.C', ever going to be used?.
CCS, does not support a linker, and requires that the entire program is in one module, or train of modules. LED.C, has to be included just like a .h file, before it will become part of the code.
Best Wishes |
|
|
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
|
Posted: Sun Nov 21, 2004 5:27 am |
|
|
Hi,
Today I tried to include the led.c in my main.c, the function "led();" are defined in led.h (not status_led.h - my mistake). But when I call led(); in my main file, the error "Function used but not defined: led" appears.
I want to call a function in a c-File (for example: main.c) which is in a other c-File (for example led.c), in my Keil Compiler for Atmel there is no problem. Is it possible to do that with the CCS Compiler too ? If yes - how ? |
|
|
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
|
Posted: Sun Nov 21, 2004 5:50 am |
|
|
I made a mistake with the c-File Name, so now the compiler knows all functions.
But an error: "A #DEVICE required before this line" is already there.
I divined the processor in main.c with the include file #include <16F684.h> there is #device....
Must I devine the #divice in all c-Modules ?
Thanks for help !!! |
|
|
Haplo
Joined: 06 Sep 2003 Posts: 659 Location: Sydney, Australia
|
|
Posted: Sun Nov 21, 2004 4:14 pm |
|
|
You only need one #device statement, and the best place to put it is the at the very first line of your code. To do this, just make sure the first line of your code is #include <16F684.h>. |
|
|
Skipper
Joined: 20 Nov 2004 Posts: 12 Location: Austria
|
|
Posted: Tue Nov 23, 2004 4:59 am |
|
|
Now I found my problem:
I put all source files in the Ordner "Source Files" in MPLAB, when I compiled the Error appears "A Device, ...."
So now I put only the main.c in the Ordner "Source Files" in this ordner the device is defined.
And the other c-Files I put in the Ordner "Other Files" - this works !!!
So I can see all Source Files in MPLAB, can edit it an the copilation is O.K. !
Thank´s all for help !!! |
|
|
|