Bitwise operations and masks: basics, help?


Results 1 to 12 of 12

Threaded View

  1. #9


    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 20:52. Reason: fixed logic
    Tim Barr

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