Embedded c-code

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

Post Reply
bert
Posts: 23
Joined: Wed Feb 28, 2007 11:58 pm
Location: The Netherlands

Embedded c-code

Post by bert »

According to the boostC manual srand() and rand() are valid functions, but this c-code block fails:

srand (FCV_RANDOM);
FCV_RANDOM = rand ();

with list of errors, including srand and rand being unknown:

C:\PICflow\projecten\lopend\Random4.c(384:2): error: unknown identifier 'srand'
C:\PICflow\projecten\lopend\Random4.c(384:2): error: failed to generate expression
C:\PICflow\projecten\lopend\Random4.c(385:13): error: unknown identifier 'rand'
C:\PICflow\projecten\lopend\Random4.c(385:13): error: failed to generate expression
C:\PICflow\projecten\lopend\Random4.c(385:13): error: invalid operand 'rand ()'
C:\PICflow\projecten\lopend\Random4.c(385:11): error: failed to generate expression

I would appear I'm doing something wrong, but what?

Bert

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: Embedded c-code

Post by Benj »

Hello Bert

To get the random function to work you have to do the following.

Firstly goto Edit -> Supplementary code and add the following line to the definitions window.

Code: Select all

#include <rand.h>
Then goto Chip -> Compiler options and add the following to the linker parameters

For a PIC16

Code: Select all

rand.pic16.lib
For a PIC18

Code: Select all

rand.pic18.lib
The Linker parameters should end up looking something like this

-ld "C:\Program Files\Matrix Multimedia\Flowcode V3\BoostC\lib" libc.pic16.lib flowcode.pic16.lib rand.pic16.lib "%f.obj" -t PIC%p -d "%d" -p "%f"

bert
Posts: 23
Joined: Wed Feb 28, 2007 11:58 pm
Location: The Netherlands

Re: Embedded c-code

Post by bert »

Thanks for your quick reply Ben! This works perfectly.

Can I leave the random library in the compiler options list or will that have a negative inpact of some sort on other projects?

Bert

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: Embedded c-code

Post by Benj »

Hello Bert

You may have to take out the code from the linker parameters if you switch to a PIC18 (or a PIC16 if you are currently using an PIC18) as it will probably cause problems then. Other then that if you are not using the random functions then the code should get optomised out.

There is a restore defaults button in the compiler options so if you do have to go back then this is possible.

bert
Posts: 23
Joined: Wed Feb 28, 2007 11:58 pm
Location: The Netherlands

Re: Embedded c-code

Post by bert »

Ok, thanks Ben!

One final question: I noticed that the libraries eeprom.pic18.lib, flash.pic18.lib and adc.pic18.lib are not present in the Flowcode boostC library directory (as opposed to the pic16 versions that are present in that directory). Can they be downloaded separately?

Bert

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: Embedded c-code

Post by Benj »

Hello Bert

These missing files are normal. Eg for the ADC routine the functions are included into our FCD files. This is also the case for the EEPROM. As for the flash im not too sure what this library would do anyway.

Regardless to say you should have no limitations between the PIC16 and the PIC18.

markmi
Posts: 2
Joined: Wed Aug 27, 2008 2:26 pm

Re: Embedded c-code

Post by markmi »

Hi Benj

I have the same problem, followed all the steps but have had no luck.
can you help? I am useing the Professional version.
started with the rnd.fcf. This is not a random number generator it only measure the time you take to remove your finger off the button.
I have attached my version for you to see where I am going wrong.

Regards,

Mark
Attachments
Random1.fcf
(8 KiB) Downloaded 678 times

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: Embedded c-code

Post by Benj »

Hello

The attached program should generate and display random numbers. Remember if your not sure how something is working then keep it as simple as possible (less to go wrong :lol: ). Also you will need to add the specific statement to the linker parameters in the Chip -> Compiler options menu mentioned above. Remember C code does not simulate but should run correctly on the hardware.
Attachments
Random2.fcf
(7 KiB) Downloaded 678 times

markmi
Posts: 2
Joined: Wed Aug 27, 2008 2:26 pm

Re: Embedded c-code

Post by markmi »

Hi Benj

The update does not compile to ASM and the HEX compiling also fails.

I have included the function, #include <rand.h> in the supplementary code and the compiler options, linker/ASM Parameters, rand.pic16.lib.

Regards,

Mark

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: Embedded c-code

Post by Benj »

Hi Mark

Sorry my mistake, the variable was named slightly wrong in the C-code.
Attachments
Random3.fcf
(7 KiB) Downloaded 884 times

Post Reply