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

*SOLVED*Error 128 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
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

*SOLVED*Error 128 A #DEVICE required before this line
PostPosted: Sun Aug 17, 2008 5:04 am     Reply with quote

Hi, im getting this error
Quote:
*** Error 128 A #DEVICE required before this line
Iknow i have dealt with this in the past but just freakin cant remember.

The device is stated in my main.c
Code:

#device PIC16F877A *=16

#include <16f877A.h>
#include <hardware.h>
#include <global.h>
#include <comms.h>
//#include <comms.c>
#include <Test_Pin.c>
#include <Xout.c>
#include <Yout.c>
#include <Zout.c>
#include <Xbuff.c>
#include <Ybuff.c>
#include <Zbuff.c>


#fuses HS,NOWDT,NOPROTECT, NOWRT, NOCPD, NOLVP, NOBROWNOUT
 // Configure Uart
 
#use delay(clock=OSC_FREQ,RESTART_WDT)
#use rs232(baud=BAUD_RATE,UART1,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
//#use rs232(baud=BAUD_RATE,xmit=TX,rcv=RX,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
 
// Configure delay
//#use delay (clock=OSC_FREQ, RESTART_WDT)
 
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

#inline
void nop()
{
#asm
  NOP
#endasm
}


Some help please Very Happy
_________________
"THE ONLY EASY DAY WAS YESTERDAY"


Last edited by jacqueskleynhans on Mon Aug 18, 2008 11:31 am; edited 1 time in total
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Aug 17, 2008 6:32 am     Reply with quote

Part of the problem are the CCS error descriptions.
I don't know your compiler version, in my compiler I get another error message.

Code:
#device PIC16F877 *=16
The PIC type number is already in the include file, now you are specifying it twice which confuses the compiler.
Change to:
Code:
#device *=16
And make sure to place this line after the 16F877A.h include.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

still not working
PostPosted: Sun Aug 17, 2008 7:00 am     Reply with quote

My Version is 4.057

I removed the device on the top of my main.c

Code:

#include <16f877A.h>
#include <hardware.h>
#include <global.h>
//#include <comms.h>
//#include <comms.c>
#include <Test_Pin.c>
#include <Xout.c>
#include <Yout.c>
#include <Zout.c>
#include <Xbuff.c>
#include <Ybuff.c>
#include <Zbuff.c>


#fuses HS,NOWDT,NOPROTECT, NOWRT, NOCPD, NOLVP, NOBROWNOUT
 // Configure Uart
 
#use delay(clock=OSC_FREQ,RESTART_WDT)
#use rs232(baud=BAUD_RATE,UART1,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
//#use rs232(baud=BAUD_RATE,xmit=TX,rcv=RX,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
 
// Configure delay
//#use delay (clock=OSC_FREQ, RESTART_WDT)
 
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

#inline
void nop()
{
#asm
  NOP
#endasm
}


And my header for pic includes

Code:
//////// Standard Header file for the PIC16F877A device ////////////////
#device PIC16F877A=*16 ADC=10 ICD=true
#nolist
//////// Program memory: 8192x14  Data RAM: 367  Stack: 8
//////// I/O: 33   Analog Pins: 8
//////// Data EEPROM: 256
//////// C Scratch area: 77   ID Location: 2000
//////// Fuses: LP,XT,HS,RC,NOWDT,WDT,NOPUT,PUT,PROTECT,DEBUG,NODEBUG
//////// Fuses: NOPROTECT,NOBROWNOUT,BROWNOUT,LVP,NOLVP,CPD,NOCPD,WRT_50%
//////// Fuses: NOWRT,WRT_25%,WRT_5%
////////
////////////////////////////////////////////////////////////////// I/O
// Discrete I/O Functions: SET_TRIS_x(), OUTPUT_x(), INPUT_x(),
//                         PORT_B_PULLUPS(), INPUT(),
//                         OUTPUT_LOW(), OUTPUT_HIGH(),
//                         OUTPUT_FLOAT(), OUTPUT_BIT()
// Constants used to identify pins in the above are:


But i am still getting the error. It says device need before this line.
But the line its refering to is the first line of my test_pin.c

Code:
void Measure_Test()
{
//setup_adc_ports(AN0);  Already set up in init
//setup_adc(ADC_CLOCK_DIV_8);
#use delay(clock=OSC_FREQ)
set_adc_channel(0);
delay_us(20);

while(1)
  {
   adc_value = read_adc();
   Test = (float)(adc_value * 5)/1024.0;   
   delay_ms(100);
  }
}

_________________
"THE ONLY EASY DAY WAS YESTERDAY"
ckielstra



Joined: 18 Mar 2004
Posts: 3680
Location: The Netherlands

View user's profile Send private message

PostPosted: Sun Aug 17, 2008 2:14 pm     Reply with quote

Some remarks:
1) If you can't find the source of a problem than try to locate the cause by making the program smaller and smaller until you have found the single line of code that is causing the problem. During this process you will often find the solution yourself and otherwise it is much easier to post here on the forum (we don't like studying large programs so you get little response).

2)
Code:
#use delay(clock=OSC_FREQ,RESTART_WDT)
This line appears at least 3 times in your program. Don't do this. Only place it once at the very start of your code.

3) NEVER change the header files supplied with the compiler. There is no need to do this and it introduces the big risk that with the next compiler release CCS changes something and your code stops to work. Problems like this are very difficult to find.
Besides all the above, you introduced a syntax error; 'PIC16F877A=*16' should have been 'PIC16F877A *=16'.
Restore the header file to it's original state and change your main.c to:
Code:
#include <16f877A.h>
#device *=16 ADC=10 ICD=true


4) Note that the #use fast_io command only works for all the code after this statement. All the C-files you have included before this statement will use the slower default_io mode.

5) The cause of your compiler complaining is most likely the sequence of instructions in your main.c. Best is to always start with the following sequence:
a) Device include file
b) Fuses settings
c) #delay and #device settings.
d) Optional other #use statements (for RS232, fast_io, etc)
e) other include files
f ) main program code
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Still not working same error
PostPosted: Mon Aug 18, 2008 10:56 am     Reply with quote

When i Compile this

Code:
#include <16f877A.h>
#device *=16 ADC=10 ICD=true
#fuses HS,NOWDT,NOPROTECT, NOWRT, NOCPD, NOLVP, NOBROWNOUT

#include <hardware.h>
#include <global.h>

#use delay(clock=OSC_FREQ,RESTART_WDT)
#use rs232(baud=BAUD_RATE,xmit=TX,rcv=RX,parity=N,bits=8,RESTART_WDT,STREAM=streamed)
#use fast_io(A)
#use fast_io(B)
#use fast_io(C)
#use fast_io(D)
#use fast_io(E)

#include <Test_Pin.c>
#include <Xout.c>
#include <Yout.c>
#include <Zout.c>
#include <Xbuff.c>
#include <Ybuff.c>
#include <Zbuff.c>


#inline
void nop()
{
#asm
  NOP
#endasm
}

void init()
{
  // Start watchdog timer with default configuration
  restart_wdt();
 

  // Configure all Ports for ADC
  Setup_ADC_Ports( ALL_ANALOG );
   
  // Initialize the port output data latches
   PORT_A = 0;
   PORT_B = 0;
   PORT_C = 0;
   PORT_D = 0;
   PORT_E = 0;

   // Setup data direction registers (1 = input)
   Set_Tris_A(0b111111);
   Set_Tris_B(0b00000000);
   Set_Tris_C(0b10000000);
   Set_Tris_D(0b00000000);
   Set_Tris_E(0b111);
   
  port_b_pullups(true);
 


   // Initialize and restart watchdog timer
  setup_counters(WDT,WDT_36MS);   // Assign prescaler (DIV 2) to WDT
  restart_wdt();

  // Setup AD clock
  SETUP_ADC( ADC_CLOCK_DIV_8);

   //Usart Asysnchronous registers setup
   SPBRG = 25;
   TXSTA = 0b00100100;

}

void main()
{
  init();

 enable_interrupts(GLOBAL);
     
  // Housekeeping
  restart_wdt();
 
while(1)
  {
  Measure_Test();
 
  printf("\f%3.2f", Test);

   
  }
}


I get this error

Quote:
Clean: Deleting intermediary and output files.
Clean: Deleted file "main.ESYM".
Clean: Deleted file "C:\Users\BETTIE\Documents\Work\main.o".
Clean: Deleted file "Test_Pin.ESYM".
Clean Warning: File "C:\Users\BETTIE\Documents\Work\Test_Pin.o" doesn't exist.
Clean: Deleted file "main.ERR".
Clean: Deleted file "Test_Pin.ERR".
Clean: Done.
Executing: "C:\Program files\Picc\CCSC.exe" +FM "main.C" +EXPORT +DF +LN +T +A +M +Z +Y=9 +EA
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Test_Pin.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Xout.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Yout.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Zout.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Xbuff.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Ybuff.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "C:\Users\BETTIE\Documents\Work\Zbuff.c" Line 8(1,1): Condition always TRUE
>>> Warning 203 "main.C" Line 83(1,1): Condition always TRUE
C:\Users\BETTIE\Documents\Work\main.o ===> 0 Errors, 8 Warnings.
Executing: "C:\Program files\Picc\CCSC.exe" +FM "Test_Pin.C" +EXPORT +DF +LN +T +A +M +Z +Y=9 +EA
*** Error 128 "Test_Pin.C" Line 1(0,0): A #DEVICE required before this line
C:\Users\BETTIE\Documents\Work\Test_Pin.o ===> 1 Errors, 0 Warnings.
Halting build on first failure as requested.
BUILD FAILED: Mon Aug 18 18:37:24 2008.


The Test_pin include is

Code:
void Measure_Test()
{

set_adc_channel(0);
delay_us(20);

while(1)
  {
   adc_value = read_adc(ADC_START_AND_READ);
   Test = (float)(adc_value * 5)/1024.0;
   Test = Test * 4.032258065l;
   Test = Test / 1.004; 
   delay_ms(100);

  }
}


I am sorry for the amount of stuff posted but something as simple as this can't get the best of me, I mean there is ppl out there with big problems.

Any suggestions, it's like the compiler wants to compile the include file as a main file ?

Thanks in advance.

Regards
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Aug 18, 2008 11:26 am     Reply with quote

Quote:
its like the compiler wants to compile the include file as a main file

Are you using MPLAB ? If so, see these links:

How to use multiple source files with MPLAB:
http://www.ccsinfo.com/forum/viewtopic.php?t=34046

More detailed information on using multiple files with MPLAB.
Read all the links in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32221

--------
Quote:
setup_counters(WDT,WDT_36MS);

The first parameter of 'WDT' is not listed in the CCS manual or the
16F877A.H file as a valid parameter for that function.
jacqueskleynhans



Joined: 10 Apr 2008
Posts: 109
Location: Cape Town, South Africa

View user's profile Send private message

Solved
PostPosted: Mon Aug 18, 2008 11:30 am     Reply with quote

Thanks alot!!!!!
_________________
"THE ONLY EASY DAY WAS YESTERDAY"
AD
Guest







ERROR DURING COMPILE CODE
PostPosted: Sun Dec 28, 2008 11:02 pm     Reply with quote

ERROR 128"MAIN887.c "line.... #device required before this line..

what should i do???i'm using pic16f887 AND CCS C compiler
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Sun Dec 28, 2008 11:24 pm     Reply with quote

Read all this stuff.

FAQ article on using CCS with MPLAB:
http://www.ccsinfo.com/faq.php?page=ccs_mplab6

Answer to a recent question to use multiple source files with MPLAB:
http://www.ccsinfo.com/forum/viewtopic.php?t=34046

More detailed information on using multiple files with MPLAB.
Read all the links in this thread:
http://www.ccsinfo.com/forum/viewtopic.php?t=32221
mas
Guest







PostPosted: Wed Dec 31, 2008 8:18 am     Reply with quote

It is not build all of the project of the menu.
It right-clicks in the source in which the project of view has main
and it compiles.
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