Embedded c-code
Embedded c-code
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
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
- 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
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.
Then goto Chip -> Compiler options and add the following to the linker parameters
For a PIC16
For a PIC18
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"
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>
For a PIC16
Code: Select all
rand.pic16.lib
Code: Select all
rand.pic18.lib
-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"
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Embedded c-code
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Embedded c-code
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
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
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Embedded c-code
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
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
- 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
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
). 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.
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

- Attachments
-
- Random2.fcf
- (7 KiB) Downloaded 678 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: Embedded c-code
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
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
- 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
Hi Mark
Sorry my mistake, the variable was named slightly wrong in the C-code.
Sorry my mistake, the variable was named slightly wrong in the C-code.
- Attachments
-
- Random3.fcf
- (7 KiB) Downloaded 884 times
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel