Bitwise operations and masks: basics, help?


Closed Thread
Results 1 to 12 of 12

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    What I would do is:
    Code:
    PORTC = PORTC & %11100000   / Clear all the bits in PORTC that are segments
    PORTC = AVAL[x] | PORTC        / sets the bits in PORTC that are '1' in AVAL[x]
    
    PORTA = PORTA & %11111001  /  Clear all the bits in PORTA that are segments
    PORTA = CVAL[x] | PORTA       / sets the bits in PORTA that are '1' in CVAL[x]
    if you just want to use one matrix for segment data you can do this:
    Code:
    ORMASK = SEGVAL[x] & %00011111 / makes sure only 5 lsb of SEGVAL[x] '1' bits get set below
    PORTC = PORTC & %11100000    / Clear all the bits in PORTC that are segments 
    PORTC = ORMASK | PORTC         / sets the bits in PORTC that are '1' in AVAL[x]
    
    ORMASK = SEGVAL[x] >> 4         / shift data 4 to right to position correct SEGVAL[x] bits for PORTA
    ORMASK = ORMASK & %0000110 / makes sure only 2 bits of SEGVAL[x] '1' bits get set below
    PORTA = PORTA | %11111001    / Clear all the bits in PORTA that are segments
    PORTA = ORMASK | PORTA        / sets the bits in PORTC that are '1' in AVAL[x]
    Last edited by falingtrea; - 18th April 2008 at 21:52. Reason: fixed logic
    Tim Barr

  2. #2
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Yup, mine is just in case something is badly define in the array, unless

    PORTA = (PORTA & %11111001) | AVAL[COUNTERA]
    PORTC = (PORTC & %11100000) | CvAL[CounterA]

    Would work anyways.
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  3. #3
    xnihilo's Avatar
    xnihilo Guest


    Did you find this post helpful? Yes | No

    Smile

    Hello,

    Thank you for this information.
    Bitwise operations are less simple than I thought but are necessary

  4. #4
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Nah not that complicated.. but once you get them they're pretty handy.
    http://en.wikipedia.org/wiki/Bitwise_operation
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts