Loading data into ONLY 4 bits of a port - is it possible?


Closed Thread
Results 1 to 7 of 7

Hybrid View

  1. #1
    Join Date
    Jan 2005
    Location
    Montreal, Quebec, Canada
    Posts
    3,172


    Did you find this post helpful? Yes | No

    Default Re: Loading data into ONLY 4 bits of a port - is it possible?

    Just a note, I prefer to use binary instead of hex.

    %11110000 is the same as $f0, except it is easy for a guy like me to use %11100000 if I want to refer to top 3 pins only.

    There no way I can remember the hex equivalent without using a conversion tool.

    Robert

  2. #2
    Join Date
    Aug 2003
    Posts
    985


    Did you find this post helpful? Yes | No

    Default Re: Loading data into ONLY 4 bits of a port - is it possible?

    You could read portb to a word variable, multiply it, read the high byte into buffera,
    zero the high byte, multiply the word var again, and copy the new high byte to bufferb.
    This would probably end up more complicated in compiled code than just shifting it.

  3. #3
    Join Date
    Aug 2005
    Location
    Michigan, USA
    Posts
    224


    Did you find this post helpful? Yes | No

    Default Re: Loading data into ONLY 4 bits of a port - is it possible?

    Hi Al (and gang),

    Can you better explain what you're trying to do, please? For example, are you trying to take bits b3..b0 in "varA" and copy them to PORTX bits RX3..RX0 and then copy bits b3..b0 in "varB" to PORTX bits RX7..RX4? It so, can you rely on "varA" and "varB" containing only 4 bits of data and simply combine them and write a single byte to PORTX which contains all 8 bits of data?

    If you're doing something else, you could always move the 'source' bits into the proper 'target' bit position and then use XOR and AND instructions to copy them to the target. Here's an (assembler) example;

    Code:
    ;
    ;  copy "varA" b3..b0 to PORTX b7..b4
    ;
            swapf   varA,W          ; move b3..b0 to b7..b4
            xorwf   PORTX,W         ; differences, hi or lo
            andlw   b'11110000'     ; don't change target b3..b0
            xorwf   PORTX,F         ; apply new b7..b4 bits

Similar Threads

  1. Assign different port bits to an array?
    By vamtbrider in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 30th November 2010, 02:40
  2. loading data to EXt. eeprom
    By MINHLE in forum General
    Replies: 0
    Last Post: - 28th December 2009, 17:56
  3. Serin2 data bits
    By Luckyborg in forum mel PIC BASIC Pro
    Replies: 0
    Last Post: - 20th February 2009, 22:10
  4. 16F88 7 data bits
    By rwskinner in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 17th February 2008, 01:05
  5. pre loading eeprom data
    By Rob Martin in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 17th April 2004, 11: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