A way to define specific ports for output bits? start output in middle port?


Results 1 to 12 of 12

Threaded View

  1. #3
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,612


    Did you find this post helpful? Yes | No

    Default Re: A way to define specific ports for output bits? start output in middle port?

    Hi,
    A bit convoluted but it hopefully shows what's happening:
    Code:
    Temp = PortB.0 & %11110001        ' Read PortB into Temp and clear bits 1-3 ( & is bitwise AND)
    Value = 5                                      ' This is the value that will be written to bits 1-3
    Value = Value << 1                          ' Shift value to the left one place to "align it" with bits 1-3 
    PortB = Temp | Value                     ' Write new value back to PortB. ( | is bitwise OR )
    Or
    Code:
    Temp = PortB.0
    Value = 5
    Temp.1 = Value.0
    Temp.2 = Value.1
    Temp.3 = Value.2
    PortB.0 = Temp
    Or, if a bit bitflipping on the port doesn't matter
    Code:
    Value = 5
    PortB.1 = Value.0
    PortB.2 = Value.1
    PortB.3 = Value 2
    And I'm sure there are other ways.

    /Henrik.
    Last edited by Ioannis; - 12th January 2013 at 12:50. Reason: Corrected the < error

Similar Threads

  1. Changing bits in a byte for multiple output
    By tazntex in forum Serial
    Replies: 3
    Last Post: - 11th August 2008, 19:10
  2. Replies: 5
    Last Post: - 30th April 2008, 20:01
  3. 28 bits --> DEC output on LCD
    By SteveB in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 1st August 2006, 19:33
  4. Serial Output 10 Bits
    By GEEZER in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 17th May 2005, 02:14
  5. Duplicating port input to port output
    By lwindridge in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 26th April 2004, 21:43

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