Assigning Two Byte Variables from Switch Settings


+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Jan 2025
    Posts
    2

    Default Assigning Two Byte Variables from Switch Settings

    I am working on a small initial project where I would like to read a six-position dip switch on RA0 to RA5.

    My intention is to assign RA0-RA3 to BYTE variable SW4 and RA4-RA5 to variable SW2. I have been able to load all six bits RA0-RA5 into SW4 using:
    Code:
    SW4 = PORTA
    Is there a way to only load bits RA0-RA3 into SW4, or is the best way to mast out bits 4 and 5 after loading the variable? And doing the same when I load the last two bits into SW2 and just mask out bits 0-3?

    I thought I had seen a variation of setting variable to only include certain bits, but unable to find that reference now.

    Thoughts?
    Thanks..

  2. #2
    Join Date
    Jan 2025
    Posts
    2


    Did you find this post helpful? Yes | No

    Default Re: Assigning Two Byte Variables from Switch Settings

    After doing some reading, I found the Logical Operator function will do exactly what I need.

    After grabbing the data from PORTA, I

    resulta = PORTA & %00001111' Returns 8-bit binary result for right four bits
    resultb = PORTA & %00110000 ' Returns 8-bit binary result for bits 4 and 5

    Just took a bit of reading, but have it working now.

    John

Similar Threads

  1. "Stretching" a byte variable into two byte variables?
    By CuriousOne in forum mel PIC BASIC Pro
    Replies: 9
    Last Post: - 25th October 2021, 00:48
  2. Assigning particular value to a variable
    By financecatalyst in forum mel PIC BASIC Pro
    Replies: 3
    Last Post: - 31st July 2011, 01:22
  3. Replies: 6
    Last Post: - 9th January 2011, 16:26
  4. Assigning a variable to only a few pins?
    By Dayaks in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 28th August 2006, 01:21
  5. Assigning TEXT strings to Variables/Arrays?
    By atomski in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 9th July 2004, 22:43

Members who have read this thread : 8

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