decimal input on portB


Closed Thread
Results 1 to 9 of 9

Hybrid View

  1. #1
    Join Date
    Jan 2013
    Location
    Texas USA
    Posts
    229


    Did you find this post helpful? Yes | No

    Default Re: decimal input on portB

    One way to accomplish this is this way.
    This will copy the upper 4 bits of the value of PORTB into a new byte variable in the lower 4 bit positions and will copy the lower 4 bits of the value of PORTB into another byte variable in the lower 4 bit positions.

    Code:
    myPortB var byte
    HighNib var byte
    LowNib  var byte
    
    
    myPortB = PortB
    HighNib = myPortB >> 4   'Right shift myPortB 4 bits, (moves bits 7:4 to bits 3:0 and then set bits 7:4 to 0)
    LowNib  = myPortB & %00001111   'Mask off bits 7:4 to 0, Only get bits 3:0
    
    So if PortB = %10010110 '$96
    Then 
    HighNib = %00001001 '$09
    LowNib  = %00000110 '$06
    Last edited by Tabsoft; - 7th April 2015 at 18:49. Reason: Clarification
    Regards,
    TABSoft

Similar Threads

  1. Decimal variable input with HSERIN command
    By pxidr84 in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 28th April 2013, 14:14
  2. PORTB.3 Input not working as expected.
    By BobEdge in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 5th March 2013, 09:58
  3. Replies: 6
    Last Post: - 12th March 2011, 13:11
  4. portb input problems
    By lockjawz in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 15th February 2011, 15:18
  5. Decimal value
    By leonel in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 7th April 2005, 16:39

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