I am working on serial to parallel converter for RECS-80 protocol.
Bit order in received signal is LSB--> MSB and I want to convert it to
MSB-->LSB format.
So how can I do this in minimum :?: ? (Because my micro is 1k Flash) please give best a solution.
Which MCU are you using? Maybe you will find the solution in the MCUs command set (or user manual) by checking the supported opcodes for shift / rotate (which can be inserted in your C / ASM code)
Hope it helped,
Maddin
It depends on the instruction set of your uC. If it has the following commands:
- shift left
- shift right
- conditional jump (if negative)
then the best approach would be to make continious left shift of initial operand with conditional jump if the result of shifted operand was negative. If it was negative (it means that the current MSB=1) then you have to add 128 to result operand and shift it right, otherwise just shift it rigth without addition. After 8 cycles of this algorithm you will get the final result. For most uC this algorithm could be implemented in less then 10 instructions.