Hello, I need to rebuild a Byte variable variables with 8 bit, I tried many ways pore not get it to work.
Can someone show me the way and help me?
thanks
Recompose byte with 8 bits
Moderator: Benj
- 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: Recompose byte with 8 bits
Hello,
You can do it like this where the input variables 0-7 contain the value 0 or 1.
Here we are making off the lower bit from the input variables by using the & 0x01.
We then add the bit value to the result variable by using the | OR command.
The left shift << is used to move each bit up to the next position, bit0 becomes bit1, bit1 becomes bit2 etc.
You can do it like this where the input variables 0-7 contain the value 0 or 1.
Code: Select all
result = (input7 & 0x01)
result = result << 1
result = result | (input6 & 0x01)
result = result << 1
result = result | (input5 & 0x01)
result = result << 1
result = result | (input4 & 0x01)
result = result << 1
result = result | (input3 & 0x01)
result = result << 1
result = result | (input2 & 0x01)
result = result << 1
result = result | (input1 & 0x01)
result = result << 1
result = result | (input0 & 0x01)We then add the bit value to the result variable by using the | OR command.
The left shift << is used to move each bit up to the next position, bit0 becomes bit1, bit1 becomes bit2 etc.
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: Recompose byte with 8 bits
Thanks Benj.
I replaced my data by variables and the code is this:
Is that correct?? because I have to compile error:
Variador_bombas_877_R4.c(2465): error: missing semicolon
Variador_bombas_877_R4.c(2467): error: missing semicolon
Variador_bombas_877_R4.c(2469): error: missing semicolon
Variador_bombas_877_R4.c(2471): error: missing semicolon
Variador_bombas_877_R4.c(2473): error: missing semicolon
Variador_bombas_877_R4.c(2475): error: missing semicolon
Variador_bombas_877_R4.c(2477): error: missing semicolon
Variador_bombas_877_R4.c(2619): error: missing semicolon
Variador_bombas_877_R4.c failure
What is "error: missing semicolon"??
Thank you very much.
I replaced my data by variables and the code is this:
Code: Select all
FCV_DAC_SEND_DATA_HI = (FCV_D7_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D6_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D5_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D4_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D3_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D2_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D1_DAC & 0x01)
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D0_DAC & 0x01)
Variador_bombas_877_R4.c(2465): error: missing semicolon
Variador_bombas_877_R4.c(2467): error: missing semicolon
Variador_bombas_877_R4.c(2469): error: missing semicolon
Variador_bombas_877_R4.c(2471): error: missing semicolon
Variador_bombas_877_R4.c(2473): error: missing semicolon
Variador_bombas_877_R4.c(2475): error: missing semicolon
Variador_bombas_877_R4.c(2477): error: missing semicolon
Variador_bombas_877_R4.c(2619): error: missing semicolon
Variador_bombas_877_R4.c failure
What is "error: missing semicolon"??
Thank you very much.
- 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: Recompose byte with 8 bits
Hello,
The code I gave you was for a calculation icon.
If your inserting directly into the C code then you need a semicolon after every line.
The code I gave you was for a calculation icon.
If your inserting directly into the C code then you need a semicolon after every line.
Code: Select all
FCV_DAC_SEND_DATA_HI = (FCV_D7_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D6_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D5_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D4_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D3_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D2_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D1_DAC & 0x01);
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI << 1;
FCV_DAC_SEND_DATA_HI = FCV_DAC_SEND_DATA_HI | (FCV_D0_DAC & 0x01);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: Recompose byte with 8 bits
Hi Benj, thanks for your help.
I put the code in the block calculation:
Variador_bombas_877_R4.c (2463:46): error: failed to generate expression
Variador_bombas_877_R4.c (2463:46): error: invalid operand '|'
And then I tried the code you put in the previous post:
Variador_bombas_877_R4.c (2498:23): warning: expression was optimized out
Variador_bombas_877_R4.c (2504:46): error: failed to generate expression
Variador_bombas_877_R4.c (2504:46): error: invalid operand '|'
Do not understand why is this error.
I put the code in the block calculation:
Variador_bombas_877_R4.c (2463:46): error: failed to generate expression
Variador_bombas_877_R4.c (2463:46): error: invalid operand '|'
And then I tried the code you put in the previous post:
Variador_bombas_877_R4.c (2498:23): warning: expression was optimized out
Variador_bombas_877_R4.c (2504:46): error: failed to generate expression
Variador_bombas_877_R4.c (2504:46): error: invalid operand '|'
Do not understand why is this error.
- 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: Recompose byte with 8 bits
Hello,
Please can you attach your program and I will take a look for you.
Please can you attach your program and I will take a look for you.
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: Recompose byte with 8 bits
Hello again Benj.
This is the program.
When I simulate the program works fine.
When compiling to pass the microcontroller fails.
Thank you.
This is the program.
When I simulate the program works fine.
When compiling to pass the microcontroller fails.
Thank you.
- Attachments
-
- descomponer_y_componer_byte.fcf
- (8.5 KiB) Downloaded 259 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: Recompose byte with 8 bits
Hello,
Right this seems to be down to a BoostC issue where it cannot logically or a byte with a piece of code in the brackets. This seems very odd so I will report it to BoostC and see if it is a bug they are aware of.
This is now compiling correctly.
Right this seems to be down to a BoostC issue where it cannot logically or a byte with a piece of code in the brackets. This seems very odd so I will report it to BoostC and see if it is a bug they are aware of.
This is now compiling correctly.
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