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 support@ccsinfo.com

24HJ128GP202 Compiler Doubt

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
pasini



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

24HJ128GP202 Compiler Doubt
PostPosted: Sun Jan 25, 2009 4:57 pm     Reply with quote

Hi, I'm using PIC24HJ128GP202, MPLAB 8.14 and CCS 4.084

I am new to 16bit MCU, but I have good knowledge of 8bits MCU and CCS compiler.

Since, PIC24 is a 16 bit compiler and from the datasheets, the statement set_tris_a(0b0000000000011111); is correct, isn't it ?

Moreover, interestingly when I try to separate my project into different .c source codes, the compiler gives me #DEVICE required error.

main.c is just
Code:

#include <24HJ128GP202.h>
#fuses HS, NOWDT
#use delay(clock=20000000)
#use rs232(stream=GPS, baud=9600, parity=N, xmit=PIN_B15, rcv=PIN_B14, bits=8, stop=1) // RX1, TX1

#include "init.h"
#include "defines.h"

void main(void)
{
   InitMCU();
   set_tris_a(0b0000000000011111);
   set_tris_b(0b0101010010000111);

   while(1)
   {   LedOn();
      BuzzerOn();
      delay_ms(20);
      LedOff();
      BuzzerOff();
      delay_ms(500);
      fputc('U', GPS);

   }
}


and init.c is
Code:

#include "init.h"
#include "defines.h"
void InitMCU(void)
{
   set_tris_a(0b0000000000011111);
   set_tris_b(0b0101010010000111);
}


I wasn't really expecting this kind of error just because I have multiple files in the project. If I include the statement #device PIC24HJ128GP202 ADC=10 another error appears saying that I cannot change the device in that piece of code.

Where can I find some tutorial to use CCS with PIC24 ?

Thanks in advance,
Luiz
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Sun Jan 25, 2009 8:06 pm     Reply with quote

The ADC #device statement needs to be right after the header include line:

Code:
#include <24HJ128GP202.h>
#device ADC=10   <==== It goes here WITHOUT the Processor declaration
#fuses HS, NOWDT
#use delay(clock=20000000)


As far as the TRIS statements go, unless you are in some really time critical
operations you don't need those lines, let the compiler take care of that
automatically for you. Besides, with the code you show you are using the TRIS statements twice in a row.
pasini



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

Error still there
PostPosted: Mon Jan 26, 2009 6:53 am     Reply with quote

I included the #device statement but the error is still there. The compiler says the error is in the init.h file ! Now files are like these:

Code:

#include <24HJ128GP202.h>
#device ADC=10
#fuses HS, NOWDT
#use delay(clock=20000000)
#use rs232(stream=GPS, baud=9600, parity=N, xmit=PIN_B15, rcv=PIN_B14, bits=8, stop=1)

#include "init.h"
#include "defines.h"

char ch;

#int_rda
void SerialInterrupt()
{    ch=fgetch(GPS);
}

void main(void)
{
   InitMCU();
   while(1)
   {   LedOn();
        delay_ms(20);
        LedOff();
        delay_ms(20);
   }
}


init.h is just <<<<<------- #device needed error is here !!!!!
Code:

void InitMCU(void);       


init.c is
Code:

#include "defines.h"
#include "init.h"

void InitMCU(void)
{
       enable_interrupts(INT_RDA);
       enable_interrupts(INTR_GLOBAL);
}



It doesn't matter if I leave blank lives of not at the beggining of init.h. The error is always in line #1 ( even if it's blank ).
If I include all functions in a single file, it compiles ok.
I think the error is not really the #device statement, but some other thing. The problem is really when I add files to the project. Can it be a CCS or MPLAB bug ?

Thanks
Pasini
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Mon Jan 26, 2009 8:49 am     Reply with quote

Are you still getting the "cannot change device" message? You don't show what is in defines.h but
make sure it has no #device or #include lines in it.
This should compile.

Code:
#include <24HJ128GP202.h>
#device ADC=10
#fuses HS, NOWDT
#use delay(clock=20000000)
#use rs232(stream=GPS, baud=9600, parity=N, xmit=PIN_B15, rcv=PIN_B14, bits=8, stop=1)

//  #include "defines.h"

char ch;

#int_rda
void SerialInterrupt()
{    ch=fgetch(GPS);
}

void InitMCU()
{
       enable_interrupts(INT_RDA);
       enable_interrupts(INTR_GLOBAL);
}

void main()
{
 //
  InitMCU();
   while(1)
   {   
//        LedOn();
        delay_ms(20);
//       LedOff();
        delay_ms(20);
   }
}
pasini



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

PostPosted: Mon Jan 26, 2009 10:54 am     Reply with quote

The way you write it, I can compile the code. But the problem is when I separate the code into multiple files, such as init.h init.c and so on.
My project will increase in size so I really would like to write the code in separate files to organize everything.

With #device option you wrote I do not receive the error.

Is there any setting or parameter I am missing ? Why can't I use multiple files ? I don't understand this...

Thanks
Pasini
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Mon Jan 26, 2009 1:21 pm     Reply with quote

I don't have the PCD compiler. But traditionally, CCS doesn't use a
linker and all files are added to the main source file with #include
statements.

In a normal C compiler such as MSVC, you can #include the same
header files in each module (file). That's standard. But in CCS you
don't do it. In other words, don't put these statements in every file:
Quote:
#include "defines.h"
#include "init.h"

You are putting them in main.c and in init.c. Just put them in the main.c source file only.
pasini



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

PostPosted: Tue Jan 27, 2009 7:22 am     Reply with quote

I updated to MPLAB 8.20 and CCS 4.085 but no way I can compile the files. I tought it could be Windows Vista but even with XP I cannot compile anything.
I am becoming upset with this problem :(

Thanks
Pasini
dyeatman



Joined: 06 Sep 2003
Posts: 1923
Location: Norman, OK

View user's profile Send private message

PostPosted: Tue Jan 27, 2009 8:28 am     Reply with quote

OK Pasini,
When you compile what error are you getting and where?

Since the program I gave you works it is likely a syntax problem. After you remove all the duplicate includes as advised by PCM post a small program illustrating the problem so we can look at it and try to help.
pasini



Joined: 12 Dec 2005
Posts: 50
Location: Curitiba - Brazil

View user's profile Send private message Send e-mail

PROBLEM SOLVED AND UNDERSTOOD !!!!!!!!!
PostPosted: Tue Jan 27, 2009 12:02 pm     Reply with quote

Hi all,
I solved the problem.
The thing is that I was including all the files in the project. As CCS answered me, I have to add the statment #include "abc.c" as a driver file in the main file. I do not need to include the file itself in the Source Files list.

I ( and others) shall do this:

main.c :
Code:

#include <24HJ128GP202.h>
#fuses FRC, NOWDT
#use delay(clock=8000000)

#include "b.c"  // <<<<<<------ it's a <<.c>> file !!!!!
#include "defines.h"

void main(void)
{
  MyFunc();
  while(1);
}


and

b.c :
Code:

void MyFunc(void)
{
  int8 c;
  for(c=0;c<10;c++);
}


Watch out !!! There are no function prototypes such as
void MyFunc(void);
in the .h file !!!!

I think (someone can confirm) that this is one of the reasons CCS is not an ANSI C compiler.
Now it works fine.

Thanks for any help
Pasini
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