View previous topic :: View next topic |
Author |
Message |
micro17
Joined: 02 Mar 2014 Posts: 14
|
Error "#DEVICE required before this line" |
Posted: Fri Nov 28, 2014 3:13 pm |
|
|
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
|
|
Posted: Fri Nov 28, 2014 5:36 pm |
|
|
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:
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
|
|
Posted: Fri Nov 28, 2014 5:47 pm |
|
|
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
|
|
Posted: Fri Nov 28, 2014 6:26 pm |
|
|
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
|
|
Posted: Fri Nov 28, 2014 6:33 pm |
|
|
Is the code that you posted really the exact same file that you are
trying to compile ? |
|
|
micro17
Joined: 02 Mar 2014 Posts: 14
|
|
Posted: Fri Nov 28, 2014 6:35 pm |
|
|
yes, is identical
I guess not specified the device.....why? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
|