Is C-code costomization of variable-declaration possible?

For C and ASSEMBLY users to post questions and code snippets for programming in C and ASSEMBLY. And for any other C or ASM course related questions.

Moderators: Benj, Mods

Post Reply
Andreas
Posts: 17
Joined: Tue Jan 17, 2017 6:10 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Is C-code costomization of variable-declaration possible?

Post by Andreas »

Hey

Is it possible to costomize the C-code in connection to variable declaration in FlowCode 7? I have found out that it is possible with most of the blocks in the Flow-diagram, but i can't find the functionality in connection to variable declarations.

I'm working on a project with 3 arrays which is placed in two memory Banks of a PIC16F88. However I would like to enlarge all of them, so that 3-banks are needed however, this makes the XC8 compiler complain about not beeing able to find space for all 3 arrays, so I would like to see what happens if I force the variables to be in certain banks by the use of absolute variables, which implies that I need to add the following to the declaration of the variables: '@ address'.

My goal is to make 3 60-byte arrays fit into 3-banks of 80 or 96 bytes each. All other variables in the program should be able to fit in the remaining space of the microcontroller.

- Andreas

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Is C-code costomization of variable-declaration possible

Post by Benj »

Hello Andreas,

Yes this is possible using the AddVar event macro.

I've attached an example for you which generates the following code.
AddVar_Override.fcfx
(8.8 KiB) Downloaded 343 times

Code: Select all

MX_GLOBAL MX_UINT8 FCV_TESTVAR[FCVsz_TESTVAR] @ 0x1000;

Andreas
Posts: 17
Joined: Tue Jan 17, 2017 6:10 pm
Has thanked: 4 times
Been thanked: 1 time
Contact:

Re: Is C-code costomization of variable-declaration possible

Post by Andreas »

Hej Benj

Thank you so much for your answer, it just worked right away. Only a few changes had to be made to make it work for all three variables. You have saved my day.

Events is a bit new to me, and until now I didn't really think it could be used to much else than simulation purposes, which I still find irrelevant for me. But I see now that events might be useful for me later. So I would like to hear if you can tell me if there is somewhere I can read about the different Events? For example how can one know that three parameters are needed for the macro associated with the AddVar event you used?

- Andreas

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Is C-code costomization of variable-declaration possible

Post by Benj »

Hi Andreas,

You can find a complete breakdown of the simulation API and Events here.
https://www.matrixtsl.com/wikiv7/index. ... ctionality

It's very powerful but we need to keep working on the documentation to bring it up a level so it's usable and easy to work with.

To enable a new event you simply go to the events tab of the project explorer window, click the event you want to use and then double click the create new macro and it will automatically create you a macro with all the relevant parameters etc.

The GetVarSize is another useful one for manipulating the size of an array variable at compile time, maybe based on a user property.

Post Reply