Assign 2 variables for 1 port..


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    oldtoddler, This is how I would approch it:

    BUSD VAR PORTD
    A VAR BYTE
    B VAR BYTE

    LET A=10 (sets A bits 0..3 into %1010 = "10")
    LET B=12 (sets B bits 0..3 into %1100 = "12")

    BUSD = (B << 4) + A

    Dave Purola,
    N8NTA

  2. #2
    oldtoddler's Avatar
    oldtoddler Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Dave
    oldtoddler, This is how I would approch it:

    BUSD = (B << 4) + A

    Dave Purola,
    N8NTA
    Thnx a lot Dave, my binary operations "department" needs little training... o:-)

    Excellent, this will work fine for me.
    For curiosity, what will happen if A>%1111 - does it have any effect ? (+ operand)

    /MRa

  3. #3
    Join Date
    Mar 2003
    Location
    Commerce Michigan USA
    Posts
    1,166


    Did you find this post helpful? Yes | No

    Default

    oldtoddler, You should mask variable A for $1111 as adding it to B would be incorrect as far as binary. You should use something like A=A & %00001111 or A=A MIN 15. These statements will limit variable A to a maximum value of 15 or binary %00001111. You could just add the mask as such:
    BUSD = (B << 4) + (A & 15)

    Dave Purola,
    N8NTA

  4. #4
    oldtoddler's Avatar
    oldtoddler Guest


    Did you find this post helpful? Yes | No

    Thumbs up

    Quote Originally Posted by Dave
    You could just add the mask as such:

    BUSD = (B << 4) + (A & 15)

    N8NTA
    Neat! Getting better all the time..
    Thnx Dave, I'm getting the idea..

    --
    a = (b>c) ? (d=e,d+f) : (g=h,g+i);

Similar Threads

  1. Variables and port pins
    By PeterReed in forum mel PIC BASIC
    Replies: 2
    Last Post: - 22nd September 2009, 15:01
  2. cant get my Lcd to work using Pic18f452
    By civicgundam in forum General
    Replies: 13
    Last Post: - 7th October 2007, 01:13
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 21:36
  4. Microcontroller with 2 way paging application problem
    By oneohthree in forum mel PIC BASIC Pro
    Replies: 30
    Last Post: - 20th April 2007, 18:27
  5. pins in arrays?
    By scorpion in forum mel PIC BASIC Pro
    Replies: 16
    Last Post: - 17th September 2005, 09:18

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