View previous topic :: View next topic |
Author |
Message |
bignash13
Joined: 14 Apr 2013 Posts: 2
|
beginner for Can bus using 18F25K80 |
Posted: Sun Apr 14, 2013 11:08 pm |
|
|
hi
I have school project that I must connect PICs by CAN bus. And I connect 18F25K80 with a built-in CAN bus module to mcp2551. But when I include <can-18F4580.c> or <can-18Fxxx8.c> in the code, it reminds me of "A #DEVICE required before this line" (in the header file).
Any help will be appreciated!!
Thanks! |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19608
|
|
Posted: Mon Apr 15, 2013 12:51 am |
|
|
Are you possibly using MPLAB?.
If so, the include file _must not_ be included in the 'source files' tab. Only in the 'header files' tab. If you put it in the source files tab, MPLAB will try to compile this code "on it's own", and will give the error you have.
If not, then the order of stuff in your main source file must be:
1) Processor include file.
2) Fuses
3) Clock statement
4) Things like RS232 and SPI #use statements
5) Other includes like the can one
6) code
If you use the wizard, it'll put 1 to 4, together in a project include file, but the order things are actually handled, must basically remain the same.
Best Wishes |
|
|
bignash13
Joined: 14 Apr 2013 Posts: 2
|
|
Posted: Mon Apr 15, 2013 1:13 am |
|
|
Thanks. It really helps. I am using MPLAB.
Can I include <can-18xxx8.c> file directly for the mcu 18F25k80?
or I have to write another can module function by myself to match 18F25k80?
my code is quite simple. MPLAB gives me the error"*** Error 128 "C:\Program Files\PICC\drivers\can-18xxx8.h" Line 82(1,2): A #DEVICE required before this line"
Best wishes
Code: |
#include <18F25k80.h>
#fuses NOWDT,INTRC_IO
#use delay(clock=8000000)
#include <can-18xxx8.c>
void main(void)
{
can_init();
}
|
|
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19608
|
|
Posted: Mon Apr 15, 2013 3:20 am |
|
|
In the MPLAB file list window, remove the can file from the 'source files' branch, and add it to the 'header files' branch.
Use can-18F4580, not 18xxx8. The latter is for the CAN module, the former is for the _ECAN_ module, which your chip has.
Best Wishes |
|
|
|