The Function works fine as is but for the sake completion here it is as a demo Program:
' ReOrder.gcb#chip 16F877A#option explicitdir portB outdir portC outdim TestData as ByteTestData = 0b10001100PortB = TestDataPortC = ReOrder(TestData)EndFunction ReOrder( DataIn as Byte ) as Byte Dim DataOut as Byte Dim NumBits as Byte For NumBits = 1 to 8 Rotate DataIn Right Rotate DataOut Left Next ReOrder = DataOutEnd Function
OK, I am lost in the function call. What is the significance of DataIn.....seems parameters were passed but I am not following what all is happening within. Anyone can shed some light?
-Nick
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Just feed it the byte you want reversed and it does so. i.e.:
ByteToSend = Reorder( ByteToSend )
Thats it.
It works by treating two bytes as 1 bit Stacks, each 8 levels deep, and the Carry flag as a variable.
But to use it you don't need to understand how it works, just accept it as some bit level trickary for now, or take a look at the help pages for the Rotate function and see if you can work out the trick from there.
Cheers
Chris
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I am sure there is a smarter way!!!
Untested. This should work.
Var = var XOR 0xff
That will invert the Bits not reverse the order.
Without the ability to address the bit indirectly i.e. var.getbit your earlyer suggestion of tmp.0 = org.7 is the best bet.
Untested but as I hate to shoot somthing down without offering an alternative here it is:
this function may work as requested:
I have no hardware handy to test right now and it is almost midnight, but will do so in the morning.
Cheers
Chris
I will give it a try!
Anobium.
Thanks! It was tedious, but used cut and paste and replace function to do 3 bytes.
Nick
Last edit: Macgman2000 2017-04-10
Morning,
The Function works fine as is but for the sake completion here it is as a demo Program:
The results in the Simulator are:
Cheers
Chris
Last edit: Chris Roper 2017-04-11
OK, I am lost in the function call. What is the significance of DataIn.....seems parameters were passed but I am not following what all is happening within. Anyone can shed some light?
-Nick
Just feed it the byte you want reversed and it does so. i.e.:
ByteToSend = Reorder( ByteToSend )
Thats it.
It works by treating two bytes as 1 bit Stacks, each 8 levels deep, and the Carry flag as a variable.
But to use it you don't need to understand how it works, just accept it as some bit level trickary for now, or take a look at the help pages for the Rotate function and see if you can work out the trick from there.
Cheers
Chris