Extracting Bits from Variables in PIC Microcontrollers

  • Thread starter Thread starter Magna Visus
  • Start date Start date
  • Tags Tags
    Microcontroller
Click For Summary
SUMMARY

The discussion focuses on extracting specific bits from two 8-bit variables, var1 and var2, in the context of the PIC P18F2520 microcontroller. The user seeks a method to obtain the 4 least significant bits from var1 and the 4 most significant bits from var2 to create a new variable, var3. A solution is provided that involves masking the unwanted bits to zero and using the logical OR operator to combine the results. This approach effectively replaces the need for a non-existent movbit function.

PREREQUISITES
  • Understanding of PIC P18F2520 microcontroller architecture
  • Familiarity with bit manipulation techniques
  • Knowledge of logical operators in C programming
  • Experience with variable declaration and memory management in embedded systems
NEXT STEPS
  • Research bit manipulation techniques in C for embedded systems
  • Learn about masking techniques for isolating bits
  • Explore the use of logical operators in microcontroller programming
  • Investigate the capabilities of the PIC P18F2520 instruction set
USEFUL FOR

Embedded systems developers, microcontroller programmers, and anyone working with bit-level data manipulation in PIC microcontrollers.

Magna Visus
Messages
23
Reaction score
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
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...
 
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!
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
2K
Replies
5
Views
4K
Replies
2
Views
2K
  • · Replies 51 ·
2
Replies
51
Views
4K
  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
5
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 1 ·
Replies
1
Views
2K