Extracting Bits from Variables in PIC Microcontrollers

In summary, the conversation discusses a method for moving specific bits from two variables, var1 and var2, to fill a new variable, var3. The suggested solution involves using logical operators to mask off unwanted bits and then OR the two bytes together. The speaker expresses gratitude for the answer and plans to use it.
  • #1
Magna Visus
24
0
Hello guys!

The following question is related to the P18F2520 series.

Suppose you have 2 defined variables var1 and var2 each containing 8 bits from a certain source.

However I only need the 4 least significant bits from var1 and the 4 most significant bit from var 2 in order to fill up a new variable var3.

Any clue how to do this? (I need a command analogue to MOVFF but regarding moving single bits)

Thank you!
 
Engineering news on Phys.org
  • #2
Magna Visus said:
Hello guys!

The following question is related to the P18F2520 series.

Suppose you have 2 defined variables var1 and var2 each containing 8 bits from a certain source.

However I only need the 4 least significant bits from var1 and the 4 most significant bit from var 2 in order to fill up a new variable var3.

Any clue how to do this? (I need a command analogue to MOVFF but regarding moving single bits)

Thank you!

Mask off the unwanted bits to 0 and then OR the two bytes...
 
  • #3
Ah didn't think about using logical operators for this task. Thought that a movbit function exist.
Thanks for your answer I'll definitely use it!
 

1. What is a PIC microcontroller?

A PIC microcontroller is a small computer chip that is used to control electronic devices. It contains a central processing unit (CPU), memory, and input/output pins. It is often used in embedded systems, such as in household appliances, automotive systems, and industrial equipment.

2. What are the advantages of using a PIC microcontroller?

There are several advantages to using a PIC microcontroller. It is small in size, low cost, and has low power consumption. It also has a wide range of peripherals and is easy to program. Additionally, it has a large user community and a variety of development tools available.

3. How do I program a PIC microcontroller?

PIC microcontrollers can be programmed using various programming languages, including assembly language and high-level languages such as C and BASIC. There are also development tools, such as compilers and integrated development environments (IDEs), that can be used to write and debug code for PIC microcontrollers.

4. Can a PIC microcontroller be used for both analog and digital applications?

Yes, a PIC microcontroller can be used for both analog and digital applications. It has built-in analog-to-digital converters (ADCs) and can also be connected to external analog components. This allows for a wide range of applications, from simple digital tasks to more complex analog tasks.

5. Are there different types of PIC microcontrollers available?

Yes, there are various types of PIC microcontrollers available, each with different features and capabilities. Some factors to consider when choosing a PIC microcontroller include the number of input/output pins, amount of memory, clock speed, and special features such as USB connectivity or motor control capabilities.

Similar threads

  • Electrical Engineering
Replies
6
Views
1K
  • Computing and Technology
Replies
0
Views
131
Replies
2
Views
2K
  • Calculus
Replies
1
Views
964
  • Electrical Engineering
Replies
2
Views
5K
  • Mechanical Engineering
Replies
30
Views
2K
Replies
2
Views
1K
  • Programming and Computer Science
Replies
7
Views
1K
  • Science and Math Textbooks
Replies
4
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
Back
Top