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 "#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
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

Error "#DEVICE required before this line"
PostPosted: Fri Nov 28, 2014 3:13 pm     Reply with quote

Help me please, problem with this code...


/*
LED on gpio.1 blinks at rate controlled by
potentiometer connected to gpio.0
*/

#include <12f683.h>
#device adc = 10 Error "#DEVICE required before this line"
#use delay(clock=8000000)
#fuses nowdt,intrc_io,put,noprotect,brownout,nomclr,nocpd

#define LED PIN_A1 // define pin for LED

int16 ad = 0; // holds 10-bit a/d value 0 to 1023

void init(void) // hardware initialization
{
output_low(LED); // LED off on boot
set_tris_a(0x01); // gpio.0 input, rest outputs
setup_oscillator(OSC_8MHZ); // set for 8MHz internal osc
setup_adc_ports(AN0_ANALOG); // a/d enabled on gpio.0
setup_adc(ADC_CLOCK_DIV_16); // a/d clock /16 @8MHz,Tad=2uS
setup_comparator(NC_NC_NC_NC); // disable comparator module
}

void Blink(int16 adval)
{
int16 rate;
rate=adval*2; // ~0-2Hz blink rate

output_high(LED); // LED on. gpio.1 o--/\/\/\---|>|---o gnd
delay_ms(rate); // blink delay 330 LED
output_low(LED); // LED off
delay_ms(rate); // delay before return
}

void main(void)
{
init(); // configure hardware
while(1) // continuous loop
{
set_adc_channel(0);// set a/d channel to gpio.0
delay_us(50); // delay for acquisition
ad = read_adc(); // read a/d into ad variable
Blink(ad); // blink LED at rate set by 10-bit a/d value
}
}
/******************* The End ********************/
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 28, 2014 5:36 pm     Reply with quote

I copied your code into an MPLAB project and it compiled OK with the
PCM compiler. The 12F683.h file has the #device statement in it for
the PIC. It's near the top of the file and looks like this:
Code:
#device PIC12F683

Did you edit the file and remove that line ?

Or did you accidentally remove the # sign at the start of the #include
line ? That will also cause the error. Example:
Code:

include <12f683.h>
#device adc = 10 Error "#DEVICE required before this line"
#use delay(clock=8000000)
#fuses nowdt,intrc_io,put,noprotect,brownout,nomclr,nocpd

#define LED PIN_A1 // define pin for LED
SuperDave



Joined: 22 May 2008
Posts: 63
Location: Madison, TN

View user's profile Send private message Visit poster's website

PostPosted: Fri Nov 28, 2014 5:47 pm     Reply with quote

If you right click on the <12F683.h> and select 'Open file at cursor', does the file open? If it doesn't then you really haven't specified a device.

It's a 10 bit adc so that line is superfluous unless you want to right or left shift it. (default is left shifted in 16 bits.) What happens if you comment it out. Perhaps removing it will give a different error and help find the problem.
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

PostPosted: Fri Nov 28, 2014 6:26 pm     Reply with quote

yes, i delete "#device adc = 10"
now i get error at line 1 "Too many nested #INCLUDEs"


Thank you very much for responses..
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 28, 2014 6:33 pm     Reply with quote

Is the code that you posted really the exact same file that you are
trying to compile ?
micro17



Joined: 02 Mar 2014
Posts: 14

View user's profile Send private message

PostPosted: Fri Nov 28, 2014 6:35 pm     Reply with quote

yes, is identical
I guess not specified the device.....why?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 28, 2014 8:16 pm     Reply with quote

Somehow, I feel that you have edited the CCS file, 12F683.h.
Make sure that file doesn't have any #include statements in it.
You should be using the official, unedited, CCS file in this directory:
Quote:
c:\program files\picc\devices\12f683.h

Look in your project directory and make sure that there is no 12F683.h
file in it. If there is one, delete it. Only the file in the directory above
should be used. The compiler will use it automatically.


Here are some older threads that discuss the problem of
"Too many nested #INCLUDEs":
http://www.ccsinfo.com/forum/viewtopic.php?t=43732&highlight=nested+includes
http://www.ccsinfo.com/forum/viewtopic.php?t=49729&highlight=nested+includes

Or just re-install the compiler.
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