Recompose byte with 8 bits

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
tello
Posts: 94
Joined: Wed Jan 16, 2013 11:37 am
Has thanked: 56 times
Been thanked: 16 times

Recompose byte with 8 bits

Post by tello »

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

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: Recompose byte with 8 bits

Post by Benj »

Hello,

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)
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.

tello
Posts: 94
Joined: Wed Jan 16, 2013 11:37 am
Has thanked: 56 times
Been thanked: 16 times

Re: Recompose byte with 8 bits

Post by tello »

Thanks Benj.

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)

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.

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: Recompose byte with 8 bits

Post by Benj »

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.

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);

tello
Posts: 94
Joined: Wed Jan 16, 2013 11:37 am
Has thanked: 56 times
Been thanked: 16 times

Re: Recompose byte with 8 bits

Post by tello »

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.

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: Recompose byte with 8 bits

Post by Benj »

Hello,

Please can you attach your program and I will take a look for you.

tello
Posts: 94
Joined: Wed Jan 16, 2013 11:37 am
Has thanked: 56 times
Been thanked: 16 times

Re: Recompose byte with 8 bits

Post by tello »

Hello again Benj.
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

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: Recompose byte with 8 bits

Post by Benj »

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.
descomponer_y_componer_byte.fcf
(8.5 KiB) Downloaded 273 times

tello
Posts: 94
Joined: Wed Jan 16, 2013 11:37 am
Has thanked: 56 times
Been thanked: 16 times

Re: Recompose byte with 8 bits

Post by tello »

Hi Benj, I tried the version you've corrected and works very well.
Thank you very much for your help. :D

Post Reply