4 posts in this topic

I am having problem working with Mitsubishi FX5 PLC.

How to send two bytes data into one word.

I want to send first byte into lower word and second byte into upper word.

Share this post


Link to post
Share on other sites

the same way you would do that with digits in a decimal system. if you want 3 and 8 to become 38, you multiply first one by ten then add the second one.

in case of 8-bit, you multiply first one by 256 or simply shift it left 8 places then add or OR result with the second byte.

 

Share this post


Link to post
Share on other sites

instead of shifting the bits you can use the swap instruction

1.) MOV HighByteValue  D1                 // move the High-Byte to D1 (this will be stored in the lower 8 Bit of D1)
2.) SWAP D1                                        // swap Hi/Lo of D1 (High-Byte-Value will stored in the upper 8 Bit of D1)
3.) WOR LowByteValue D1                  // OR the value of the Low-Byte of D1 

 

 

Share this post


Link to post
Share on other sites

yup, that will work too.  as usual there are many ways to get the same result.

on a side note - without knowing where the data comes from and what the result is used for, i would just suggest some caution with data manipulation. you may want to check or ensure that "byte values are indeed only 8 bits or you may get surprise result. 

if the byte values are from some bitwise memory like I/O or M, you can use form that only takes 8 bits (for example K2M100). if the byte values are stored in D registers you may want to clear higher bits..

 

for example

WAND HFF  HighByteValue HighByteValue  

WAND HFF  LowByteValue LowByteValue

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now