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

Error: A #DEVICE required before this line

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



Joined: 20 Nov 2004
Posts: 12
Location: Austria

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

Error: A #DEVICE required before this line
PostPosted: Sat Nov 20, 2004 5:31 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website MSN Messenger

PostPosted: Sat Nov 20, 2004 5:42 am     Reply with quote

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







PostPosted: Sat Nov 20, 2004 5:45 am     Reply with quote

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

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

PostPosted: Sat Nov 20, 2004 6:11 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sat Nov 20, 2004 6:18 am     Reply with quote

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

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

PostPosted: Sat Nov 20, 2004 6:32 am     Reply with quote

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

View user's profile Send private message Send e-mail Visit poster's website

PostPosted: Sat Nov 20, 2004 9:24 am     Reply with quote

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







PostPosted: Sat Nov 20, 2004 11:05 am     Reply with quote

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

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

PostPosted: Sun Nov 21, 2004 5:27 am     Reply with quote

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

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

PostPosted: Sun Nov 21, 2004 5:50 am     Reply with quote

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

View user's profile Send private message

PostPosted: Sun Nov 21, 2004 4:14 pm     Reply with quote

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

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

PostPosted: Tue Nov 23, 2004 4:59 am     Reply with quote

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 !!!
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