Hello Matrix Team,
question ist it possible to use the follwing C-code inside FC in a C-Box
/*
Enter C code below this comment
*/
/* 8-bit CRC polynomial X^8 + X^2 + X + 1 */.
#define FCV_POLY 0x07
unsigned char update_crc (unsigned char FCV_CRC, unsigned char FCV_CRC_SEED)
{
unsigned char FCV_CRC_U;
unsigned char FCV_I;
FCV_CRC_U = FCV_CRC;
FCV_CRC_U ^= FCV_CRC_SEED;
for (FCV_I=0; FCV_I<8; FCV_I++)
{
FCV_CRC_U = ( FCV_CRC_U & 0x80 ) ? FCV_POLY ^ ( FCV_CRC_U << 1 ) : ( FCV_CRC_U << 1 );
}
return FCV_CRC_U;
}
unsigned char crc8 (unsigned char *FCV_CRC, unsigned char FCV_CRC_LENGTH)
{
unsigned char FCV_CRC_UP = 0;
unsigned char FCV_C;
for(FCV_C=0;FCV_C < FCV_CRC_LENGTH; FCV_C++) {
FCV_CRC_UP = update_crc (FCV_CRC[FCV_C], FCV_CRC_UP);
}
return FCV_CRC_UP;
}
Attached the FC file too.
THX in advance
Dirk
CRC calculation inside C-Box
-
- Posts: 89
- http://meble-kuchenne.info.pl
- Joined: Fri Dec 04, 2020 11:03 am
- Has thanked: 6 times
- Been thanked: 12 times
CRC calculation inside C-Box
- Attachments
-
- CRC8_c_code_V_1_0.fcfx
- (10.77 KiB) Downloaded 53 times
Happy FC9, FC-8 and FC-6 professional user
-
- Valued Contributor
- Posts: 162
- Joined: Wed Dec 02, 2020 7:28 pm
- Has thanked: 68 times
- Been thanked: 58 times
Re: CRC calculation inside C-Box
That won’t work because you can not define new functions within a macro (which is a function). It should not be difficult to rewrite the C code as macro. Or you can add the C code in the supplementary code.
-
- Valued Contributor
- Posts: 991
- Joined: Wed Dec 09, 2020 9:37 pm
- Has thanked: 106 times
- Been thanked: 517 times
Re: CRC calculation inside C-Box
Note that you could create a second function (crc8). You can call FC macros from within C using FCM_macroname(args) - the easiest way to see the arguments needed is to look at the C code for a macro, and this is one instance where names do not get capitalised.
As pointed out - it would probably be more sensible to convert to a couple of FC macros in this instance.
Martin
As pointed out - it would probably be more sensible to convert to a couple of FC macros in this instance.
Martin
-
- Matrix Staff
- Posts: 1269
- Joined: Sat Dec 05, 2020 10:32 am
- Has thanked: 168 times
- Been thanked: 285 times
Re: CRC calculation inside C-Box
It is possible, but C code icons within the flowcharts in Flowcode are not ideally suited to contain full C functions. A better place to store functions within "supplementary code" (under Build->Project Options). You can then call these functions from your flowchart using a C code icon.
I also notice you are using variable names within your C code that start with "FCV_". I would avoid this because they could clash or cause confusion with variables created within Flowcode. In your own C functions you should use 'normal' variable names rather than the names of Flowcode variables. The exception is when you want to refer to Flowcode variables within your C code (e.g. when passing Flowcode variables to your functions).
I have attached a simple example project of using Supplementary Code within Flowcode. And here are some images from the example.
I also notice you are using variable names within your C code that start with "FCV_". I would avoid this because they could clash or cause confusion with variables created within Flowcode. In your own C functions you should use 'normal' variable names rather than the names of Flowcode variables. The exception is when you want to refer to Flowcode variables within your C code (e.g. when passing Flowcode variables to your functions).
I have attached a simple example project of using Supplementary Code within Flowcode. And here are some images from the example.
- Attachments
-
- Supplementary Code example.fcfx
- (7.27 KiB) Downloaded 57 times
Re: CRC calculation inside C-Box
Good afternoon,
i am new
work with Pic16F18877, BL0080, Uart, Flowcode V10
i have to transmit 9 byte data and a 2 byte checksum with CRC-CCITT16-polynom 0x8408
i have found a nice example
CRC8_c_code_V_1_2.fcfx
do you have also a example with CCITT16-polynom 0x8408
or can you help ?
best regards
Hermann Pirklbauer - Austria
i am new
work with Pic16F18877, BL0080, Uart, Flowcode V10
i have to transmit 9 byte data and a 2 byte checksum with CRC-CCITT16-polynom 0x8408
i have found a nice example
CRC8_c_code_V_1_2.fcfx
do you have also a example with CCITT16-polynom 0x8408
or can you help ?
best regards
Hermann Pirklbauer - Austria