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

Using CCS in MPLAB

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



Joined: 30 May 2023
Posts: 12

View user's profile Send private message

Using CCS in MPLAB
PostPosted: Tue May 30, 2023 2:49 pm     Reply with quote

Looking into the possibility of using CCS within MPLAB. I understand CCS compiler users typically just #include extra C files as is the case with the legacy code that I'm using. In trying this code in MPLAB, it will not compile by dumping all C files into the source folder but will compile if I just put main in the source folder.

Problem is I get a ton of "unable to reference identifier" issues so it makes following definitions from file to file difficult. Is there a correct way to organize legacy CCS source files within the MPLAB folder structure?

I've tried putting all other C files in the library folder, but the navigation issues remain. Probably just missing something easy here.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Wed May 31, 2023 1:21 am     Reply with quote

First, are you talking MPLAB, or MPLAB X?. Big difference.
Assuming MPLAB X.

In the project, just put the main CCS file in 'source files'. Nothing else.
Have this file #include it's component files.
Don't try to put things into the mplab folders. These are it's to control. Just
Create your own project directory, and put your files in this. Then in MPLAB,
create the 'project', and in the project tab, select the source files tab, right
click and add the main CCS file as existing item.
What is happening is that by putting them into the MPLAB folders, it is
performing an automatic 'add existing items from folder' for these files
to the project, putting them is as items to each be compiled, not building
the correct project structure.
You can correct the structure by removing every file except the main CCS
file from the Source files tab in the project. Instead drag them into the
Header Files tab. This then tells MPLAB, not to try to directly compile these
files individually.
temtronic



Joined: 01 Jul 2010
Posts: 9221
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed May 31, 2023 4:50 am     Reply with quote

also...
when using MPLAB ( v8.92 is the last one I think..), there's an option called 'Build Configuration' which can be 'Debug' or 'Release'. You need to select 'Release' and then compile to create the proper code to download into the PIC for 'real World' operation. The 'Debug' option stuffs 'extra' code in so you can use their simulator and test from within the PC.
ncdoody



Joined: 30 May 2023
Posts: 12

View user's profile Send private message

PostPosted: Wed May 31, 2023 8:53 am     Reply with quote

Apologies, I'm trying to use MPLAB X. v6.05

@Ttelmah I think I follow what you're saying up until...
"Instead drag them into the Header Files tab. This then tells MPLAB, not to try to directly compile these files individually."
Maybe I don't understand what you mean by the "Header Files tab" or dragging them in. Anytime I try putting C files (by Add Existing Item) in the headers folder it tries to compile the C files just as if I put them in with main.c. Such as:

"C:\PROGRA~2\PICC\CCSCON.exe" out=""build/default/production"" main.c +EXPORT +FH +DF +CC +Y=9 +EA +DF +LN +T +A +M +J +Z -P #__18C252=1 +EXPORTD="build/default/production"
"C:\PROGRA~2\PICC\CCSCON.exe" out=""build/default/production"" Analog.c +EXPORT +FH +DF +CC +Y=9 +EA +DF +LN +T +A +M +J +Z -P #__18C252=1 +EXPORTD="build/default/production"
Compiling C:\Users\User\MPLABXProjects\project\Analog on 31-May-23 at 10:30
C:\Users\User\MPLABXProjects\project\Analog.c:30:9: Error#128 A #DEVICE required before this line
C:\Users\User\MPLABXProjects\project\Analog.o ===> 1 Errors, 0 Warnings.
Build Failed.

Compiles just fine with or without placing just true header files in the header folder, but original navigation reference issue remains.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Wed May 31, 2023 9:48 am     Reply with quote

In the MPLAB IDE, you have 'projects'. These contain branches for
header files, libraries etc.. The point is you select the files in the
source files branch, and drag these into the header files branch. It is this
that determines how MPLAB treats the files. All files in the 'source files'
branch are compiled separately, which is not what is wanted.
ncdoody



Joined: 30 May 2023
Posts: 12

View user's profile Send private message

PostPosted: Wed May 31, 2023 10:16 am     Reply with quote

Hmm, idk.

I get the same compile error no matter whether a second c file is in projectName\Source Files or projectName\Header Files
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

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

PostPosted: Fri Jun 02, 2023 4:18 am     Reply with quote

I've found with mplabx inc latest version, that in MPLABX projects window just have your main.c file only as the source file, then just use #include xxx.c etc in either another header file or in your main .c file.
Otherwise you will get build failed.

for example a test project I doing now works with both MPLAB 8.92 and MPLABX 6.05

my header file

StepIndex.h

Code:

#include "18F4431.h"
#device ADC=10

#fuses H4,NOWDT,NOPROTECT,NOLVP,DEBUG,NOLVP,NOBROWNOUT
#fuses NOPUT,NOIESO,NOFCMEN,NOEBTR,NOEBTRB,NOCPB
#fuses NOWRTC,NOWRT,NOSTVREN              //No Watch Dog Timer

#use delay(crystal=8MHz)

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include "Flex_LCD420.c" 
#include "keypad.c"

#define debug_led PIN_C1
 #use pwm(pwm1,timer=2,output=pin_D7,pwm_off,frequency=500,stream=stepper,duty=40)

#use standard_io(A)//using fast I/o so set each tris bit suit for inputs
#use standard_io(B)//keep all unsed ports pins as output and drive low
#use standard_io(C)
#use standard_io(D)
#use standard_io(E)

//#byte POSTCNT = 0x0F66//int16 POSTCNT  =   getenv("SFR:CAP2BUFL");
//#byte MAXCNT  = 0x0F64//  getenv("SFR:CAP3BUFL");

#define DISABLE_VELOCITY   0x80
#define QEI_OFF  0x00
#define QEI_2XINDX 0x04
#define QEI_2XPER 0x08
#define QEI_4XINDX 0x14
#define QEI_4XPER  0x18
#define VELOCITY_DIV_1 0x00
#define VELOCITY_DIV_4  0x01
#define VELOCITY_DIV_16  0x02
#define VELOCITY_DIV_64  0x03

#define dir_pin  LAT_D5
#define Ena_pin  LAT_D3

/*
#define stepper_on PIN_C0
#define stepper_off PIN_C1
*/
//#define dir_fwd PIN_C2
//#define dir_rev PIN_C3
#define led_on PIN_C4
#define led_off PIN_C5


#byte   QEICON = 0xFB6

//bits in QEICON
#define QEI_NOT_VELM 7
#define QEI_ERROR    6
#define QEI_DIRECTION 5
int16 maxcnt;
#byte maxcnt=0xf64
#byte  MAXCNTH =0xf65
#define  MAXCNTL =0xf64

int16  POSCNT,IND_MAR=0;
#byte POSCNT = 0xF66
#byte POSCNTH  = 0xF67
#define POSCNTL  = 0xF66
int16  VREG;
#byte  VREG        = 0xF68
#byte  VREGH      = 0xF69
#byte  VREGL       = 0xF68
#byte  DFLTCON   = 0xF60   //Digital Filter Control Register
#byte  CAP1CON  = 0xF63


main c file

The in MPLABX project I just add this as the main source file, I dont even add header files in the project list.

StepIndex.c
Code:



#include <StepIndex.h>
//when postcount equals maxcount
//interrupt, switch of PWM to stepper driver

#int_IC2QEI
void IC2QEI_isr()
{
int8 k;
 PWM_OFF(stepper);
output_high(ena_pin);
 POSCNT=0;
 clear_interrupt(INT_IC2QEI);
}


void main(void)
{

//test code etc

}



Hope this helps.
Ttelmah



Joined: 11 Mar 2010
Posts: 19497

View user's profile Send private message

PostPosted: Fri Jun 02, 2023 7:41 am     Reply with quote

That's exactly right.
The only point about putting the other files into the header files list,
is it allows you to click on them there to open them and look at them.
diode_blade



Joined: 18 Aug 2014
Posts: 55
Location: Sheffield, South Yorkshire

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

PostPosted: Mon Jun 05, 2023 1:15 am     Reply with quote

Ttelmah wrote:
That's exactly right.
The only point about putting the other files into the header files list,
is it allows you to click on them there to open them and look at them.


Yes good point that Ttelmah.
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