Menu

SPI Arduino (AtMega) Uno

Help
2017-03-30
2017-03-30
<< < 1 2 (Page 2 of 2)
  • Anobium

    Anobium - 2017-04-10

    I am sure there is a smarter way!!!

     
  • Anobium

    Anobium - 2017-04-10

    Untested. This should work.

    Var = var XOR 0xff

     
  • Chris Roper

    Chris Roper - 2017-04-10

    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.

     
  • Chris Roper

    Chris Roper - 2017-04-10

    Untested but as I hate to shoot somthing down without offering an alternative here it is:

    this function may work as requested:

    Function 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 = DataOut
    End Function
    

    I have no hardware handy to test right now and it is almost midnight, but will do so in the morning.

    Cheers
    Chris

     
    • Macgman2000

      Macgman2000 - 2017-04-10

      I will give it a try!

       
  • Macgman2000

    Macgman2000 - 2017-04-10

    Anobium.

    Thanks! It was tedious, but used cut and paste and replace function to do 3 bytes.

    Nick

     

    Last edit: Macgman2000 2017-04-10
  • Chris Roper

    Chris Roper - 2017-04-11

    Morning,

    The Function works fine as is but for the sake completion here it is as a demo Program:

    ' ReOrder.gcb
    
    #chip 16F877A
    
    #option explicit
    
    dir portB out
    dir portC out
    
    dim TestData as Byte
    
    TestData = 0b10001100
    
    PortB = TestData
    PortC = ReOrder(TestData)
    
    End
    
    Function 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 = DataOut
    End Function
    

    The results in the Simulator are:

    Cheers
    Chris

     

    Last edit: Chris Roper 2017-04-11
  • Macgman2000

    Macgman2000 - 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

     
  • Chris Roper

    Chris Roper - 2017-04-11

    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

     
<< < 1 2 (Page 2 of 2)

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.