Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Error: a #device required before this line ccs c

Status
Not open for further replies.

coolvasanth07

Member level 1
Joined
Sep 25, 2012
Messages
37
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Activity points
1,506
HI, WHEN COMPILE MY PROGRAM I GOT ERROR :"a #device required before this line ccs c" ,,,HOW CAN I CLEAR THIS ERROR...AM USIND PIC16F877A + CCS C,,,PLZ ANY ONE HELP ME,,,

>>THANX IN ADVANCE
 

Hello coolvasanth07, that's a common compiler error, but to know what is generating it, we must see the program.

Best Regards!
 

You need to perform device initializations/setup at the beginning of the code, such as:

Code:
// Device setup 
#include "16F877A.h" 
#device *=16 
#device adc=10

Hope this helps.
Tahmid.
 

Thanx for ur response friends..my simple code given below
Code:
#device *=16 
#device adc=10 
#include<16F877A.h>

#use delay(clock=20000000)
#byte PORT_B=6;

void main()
{
	set_tris_b(0);
	PORTB=0;
	while(true)
	{
		output_b(0xff);
		delay_ms(1000);
		output_b(0x00);
		delay_ms(1000);
	}
}

when i compile this program i get error...

Executing: "C:\Program files\Picc\CCSC.exe" +FM "F:\vasanth\samples\CCS-C Example\LED\led.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 128 "led.c" Line 1(8,13): A #DEVICE required before this line
1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Tue Jan 01 12:06:01 2013

what can i do...plz help me....
 

#device settings have to come after the #include.

So, you should write this:

Code:
#include<16F877A.h>
#device *=16 
#device adc=10 

#use delay(clock=20000000)
#byte PORT_B=6;

void main()
{
	set_tris_b(0);
	PORTB=0;
	while(true)
	{
		output_b(0xff);
		delay_ms(1000);
		output_b(0x00);
		delay_ms(1000);
	}
}

Hope this helps.
Tahmid.
 

When I do that I get a new slew of errors that I avoided before by moving the #device line to the top of the code...

error is:

Executing: "C:\Program files\Picc\CCSC.exe" +FM "F:\vasanth\samples\CCS-C Example\LED\led.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 18 "led.c" Line 1(8,19): File can not be opened
Not in project "F:\vasanth\samples\CCS-C Example\LED\16F877A.h"
*** Error 128 "led.c" Line 2(9,14): A #DEVICE required before this line
*** "led.c" Line 3: Error #128: A #DEVICE required before this line
*** "led.c" Line 6: Error #128: A #DEVICE required before this line
4 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Tue Jan 01 12:33:18 2013
 

Use "16F877A.h" instead of <16F877A.h>, like I had shown on post #3.

Hope this helps.
Tahmid.
 

i get same error only friend...see below

Code:
#include "16F877A.h"
#device *=16 
#device adc=10 

#use delay(clock=20000000)
#byte PORT_B=6;

void main()
{
	set_tris_b(0);
	PORTB=0;
	while(true)
	{
		output_b(0xff);
		delay_ms(1000);
		output_b(0x00);
		delay_ms(1000);
	}
}

error is:

Executing: "C:\Program files\Picc\CCSC.exe" +FM "F:\vasanth\samples\CCS-C Example\LED\led.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 18 "led.c" Line 1(9,20): File can not be opened
Not in project "F:\vasanth\samples\CCS-C Example\LED\16F877A.h"
*** Error 128 "led.c" Line 2(9,14): A #DEVICE required before this line
*** "led.c" Line 3: Error #128: A #DEVICE required before this line
*** "led.c" Line 6: Error #128: A #DEVICE required before this line
4 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Tue Jan 01 12:41:28 2013
 

"led.c" is the source file containing the code, right?

Did you add it under "source files" in your project? I think you didn't and that's the reason for the error.
 

i add it friend,, see below image plz...

untitled.JPG
 

Hello coolvasanth07, after seeing your code, I can see several errors. First, and as Tahmid said should be the PIC header but enclosed between the simbols <> That mean that this library is located in the default directory assigned by the compiler, in this case:

C:\Program Files\PICC\Devices

If you use "" means that the library is located in the local directory where the project files is located for example:

F:\vasanth\samples\CCS-C Example\LED

Second, you should always declare at least the minimum fuses for the code work well. Please take a look in the manual about the directive #fuses.
For a program as simple, by the moment it is not necessary to use the statement: set_tris_b(0);. To clear this, you have to study in the manual about directive: #USE STANDARD_IO (port)
Also, you must change the instruction PortB= 0; by Port_B= 0;

Then, your program may be as follows:

Code:
#include <16F877A.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)

#byte Port_B=6

void main()
{
   Port_B=0;
   while(true)
   {
      output_b(0xff);
      delay_ms(1000);
      output_b(0x00);
      delay_ms(1000);
   }
}

Best Regards!

- - - Updated - - -

Hi again coolvasanth07, The description that I gave you about the use of #include directive is something that I had knowledge to standard C. But now I have looked on that directive in the Manual of CCS and and it seems that their use is somewhat different. In the manual says:

"If a full path is not specified the compiler will use the list of directories specified for the project to search for the file. If the filename is in "" then the directory with the main source file is searched first. If the filename is in <> then the directory with the main source file is searched last."

Please look at the use of this directive in the manual.

Best Regards!
 

Hellow bmb_10 when i compile ur code
Code:
#include <16F877A.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)

#byte Port_B=6

void main()
{
   Port_B=0;
   while(true)
   {
      output_b(0xff);
      delay_ms(1000);
      output_b(0x00);
      delay_ms(1000);
   }
}

i got following errors:

Executing: "C:\Program files\Picc\CCSC.exe" +FM "led.c" +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 18 "led.c" Line 1(9,20): File can not be opened
Not in project "C:\Documents and Settings\JAVA9\Desktop\AAA\16F877A.h"
*** Error 128 "led.c" Line 2(9,15): A #DEVICE required before this line
*** "led.c" Line 4: Error #111: Unknown keyword in #FUSES "NOWDT"
*** "led.c" Line 5: Error #111: Unknown keyword in #FUSES "HS"
*** "led.c" Line 6: Error #111: Unknown keyword in #FUSES "NOBROWNOUT"
*** "led.c" Line 7: Error #111: Unknown keyword in #FUSES "NOLVP"
*** "led.c" Line 11: Error #128: A #DEVICE required before this line
7 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Wed Jan 02 09:43:33 2013
what can i do, plz tell me..
 
Last edited by a moderator:

OK, I can compile that program without problems, so it seems that you have an additional path problem. Do the following: Open CCS C compiler and go to Menu -> Options -> Project Options. It opens a new window in which you should see the following in the 'Files' tab:

- Target: PIC16F877A
- Source Files: led.c
- Project Filename: C:\Documents and Settings\JAVA9\Desktop\AAA\led.pjt

Then in the 'Include Files' tab:

- Include File Search Order:
C:\Program Files\PICC\devices
C:\Program Files\PICC\drivers

If you find any differences, then correct it and try again. What compiler version do you have?

Best Regards!
 
Last edited:

Hi pal,

Permit me to join in the discussion.i compiled your code;

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#include "C:\Users\xyz1\Desktop\xyz_new\lab tutorial.h"
#include <16F877A.h>
#device adc=16
 
#FUSES NOWDT      //No Watch Dog Timer
#FUSES HS         //High speed Osc(>4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT //No brownout reset
#FUSES NOLVP      //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
 
#use delay(clock=20000000)
 
#byte Port_B=6
 
void main()
{
   Port_B=0;
   while(true)
   {
      output_b(0xff);
      delay_ms(1000);
      output_b(0x00);
      delay_ms(1000);
   }
}




and i got thiz errors:
xxx Error 23 " C:\Program files (x86)\PICC\devices\16F877A.h" Line 2(8,9): Can not change device type this far into the code
xxx Error 48 " C:\Program files (x86)\PICC\devices\16F877A.h" Line 164(1,23): Expecting a (
xxx Error 48 " C:\Program files (x86)\PICC\devices\16F877A.h" Line 164(6,11): Expecting a (
xxx Info 300 " C:\Program files (x86)\PICC\devices\16F877A.h" Line 168(6,11): More info: First Declaration of CCP_2
xxx Error 31 " C:\Program files (x86)\PICC\devices\16F877A.h" Line 168(6,11): I dentifier is already used in this scope

whatz the remedy plz?...thanks



OK, I can compile that program without problems, so it seems that you have an additional path problem. Do the following: Open CCS C compiler and go to Menu -> Options -> Project Options. It opens a new window in which you should see the following in the 'Files' tab:

- Target: PIC16F877A
- Source Files: led.c
- Project Filename: C:\Documents and Settings\JAVA9\Desktop\AAA\led.pjt

Then in the 'Include Files' tab:

- Include File Search Order:
C:\Program Files\PICC\devices
C:\Program Files\PICC\drivers

If you find any differences, then correct it and try again. What compiler version do you have?

Best Regards!
 
Last edited by a moderator:

Hi bioda, can we see the contents of the file: C:\Users\xyz1\Desktop\xyz_new\lab tutorial.h? Also you can try to compile the code without that line. It seems that in that file has already been declared the PIC's library.

Best Regards!

- - - Updated - - -

If you want lo learn CCS (That is really easy) it is best to use the instructions specific to the CCS C compiler to realize their full potential. Here an example to turn on and off a LED:

Code:
#include <16F877A.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)

#define LED PIN_B0
#define DELAY 1000

void main()
{
   //Example blinking LED program
   while(true)
   {
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);
   }
}

Best regards!
 

hi bmb_10,

okay...thanks.

This code is error free.





Hi bioda, can we see the contents of the file: C:\Users\xyz1\Desktop\xyz_new\lab tutorial.h? Also you can try to compile the code without that line. It seems that in that file has already been declared the PIC's library.

Best Regards!

- - - Updated - - -

If you want lo learn CCS (That is really easy) it is best to use the instructions specific to the CCS C compiler to realize their full potential. Here an example to turn on and off a LED:

Code:
#include <16F877A.h>
#device adc=16

#FUSES NOWDT                    //No Watch Dog Timer
#FUSES HS                       //High speed Osc (> 4mhz for PCM/PCH) (>10mhz for PCD)
#FUSES NOBROWNOUT               //No brownout reset
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O

#use delay(clock=20000000)

#define LED PIN_B0
#define DELAY 1000

void main()
{
   //Example blinking LED program
   while(true)
   {
      output_low(LED);
      delay_ms(DELAY);
      output_high(LED);
      delay_ms(DELAY);
   }
}

Best regards!
 

OK, I can compile that program without problems, so it seems that you have an additional path problem. Do the following: Open CCS C compiler and go to Menu -> Options -> Project Options. It opens a new window in which you should see the following in the 'Files' tab:

- Target: PIC16F877A
- Source Files: led.c
- Project Filename: C:\Documents and Settings\JAVA9\Desktop\AAA\led.pjt

Then in the 'Include Files' tab:

- Include File Search Order:
C:\Program Files\PICC\devices
C:\Program Files\PICC\drivers

If you find any differences, then correct it and try again. What compiler version do you have?

Best Regards!

My compiler version >> "CCS C 4.105 Full"
 

If after making the revisions I asked you, all that is as I showed you in post #13, then it is possible that you have a problem with the compiler. V4.105 is now an old version, and it is better that you find a more recent one.

Greetings!
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top