Menu

Split a byte

Help
EA7-JFV
2024-09-03
2024-09-03
  • EA7-JFV

    EA7-JFV - 2024-09-03

    Hi,
    It's possible split a input byte?

    I need 8 input lines to input a byte, but I need split the byte, for input in two different ports:

    Something like this:
    bit3, bit2, bit1 and bit0 --> inputs in Portb.3, Portb.2, Portb.1 and Portb.0
    and
    bit7, bit6, bit5 and bit4 --> inputs in Portd.7, Portd.6, Portd.5 and Portd.4

    Its possible to do something like that?

    Thanks

     

    Last edit: EA7-JFV 2024-09-03
  • Anobium

    Anobium - 2024-09-03

    Hello,

    Do exactly what you describing.

    someByte = 0b10101010
    
    PortB = ( PortB and 0xF0 ) or ( someByte and 0x0F)  // Get existing port, get upper nibble  then OR lower nibble
    PortD = ( PortF and 0x0F ) or ( someByte and 0xF0) // get lower nibble OR with upper nibble
    
     
  • EA7-JFV

    EA7-JFV - 2024-09-03

    Oh Great!

    Mmmm... it's so simple... and bright!

    Thanks, so very much, Anobium

     
  • Anobium

    Anobium - 2024-09-03

    The libraries use this as the method for LCD and GLCDs.

    Good luck.

     
  • EA7-JFV

    EA7-JFV - 2024-09-03

    Ok
    Thanks again

     

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.