How to assign this variable?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156

    Default How to assign this variable?

    In an application, I have wired the lower 4 bits of PORTF to control the inputs of a multiplexer. Right now I have assigned the variable like this:

    MUX VAR PORTF

    but really, it's only the lower 4 bits. How can I specify that in my declaration?

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Look at section 4.10 in the manual.
    Dave
    Always wear safety glasses while programming.

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


    Did you find this post helpful? Yes | No

    Default

    There's no specific variable type for that. Usually a Shadow register & some BYTEWise operation solve many issue. Something around ....

    Code:
    MUX VAR PORTF
    S VAR BYTE
    
    S = (MUX & $F0) | ValueToWrite 
    MUX = S
    When dealing with port, you may want to avoid successive bit modification to avoid RMW effect.

    To read a PORT it's easier
    Code:
    MUX VAR PORTF
    S VAR BYTE
    
    S = MUX & $0F
    Last edited by mister_e; - 25th January 2011 at 00:45. Reason: How2Read
    Steve

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

  4. #4
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    I see how I can isolate the lower 4 bits of a port and READ from them

    anyvar = PORTF & $0f

    but don't know how that pertains to a WRITE. Is that what you mean?

  5. #5
    Join Date
    Dec 2008
    Location
    Los Angeles, CA
    Posts
    156


    Did you find this post helpful? Yes | No

    Default

    thank you mister_e.

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


    Did you find this post helpful? Yes | No

    Default

    Sorry I'd edit the post while you replied. Seems you got the idea though
    Steve

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

Members who have read this thread : 1

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