Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
Thread Tools Display Modes
Old 5th June 2007, 02:56 PM   (permalink)
Default Bit Select

Ok....This should be an easy question, but I can't find the answer because I don't know what to look for.

I am writing a program for a PIC16f684, using the PIC C lite complier.

I have a 8 bit value stored and I want to take bit x and store it in a different variable.

How do I do that?

John
jbchrist is offline   Reply With Quote
Old 5th June 2007, 03:23 PM   (permalink)
Default

I would guess,

NewVar = OldVar&(1<<X);

Would issolate the bit. (X = 0 to 7)

Mike.
Edit changed the operator to the bitwise one as PB pointed out.
Note to self, don't post at 2AM after a night out.

Last edited by Pommie; 6th June 2007 at 01:32 AM.
Pommie is offline   Reply With Quote
Old 5th June 2007, 04:47 PM   (permalink)
Default

Using the && relational operator with an actual C compiler would be a pretty hard bug to find. You should use the bitwise & operator which will get you the intended result.

I would also highly recommend that you examine carefully the compiler's assembly language output to verify that it is doing what you want it to do.
Papabravo is offline   Reply With Quote
Old 5th June 2007, 05:13 PM   (permalink)
Default

Thanks! That worked beautifully!
jbchrist is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Latest
naming a pin or bit question hotrodhed120 Micro Controllers 7 8th May 2007 04:50 PM
Sync Problem Marc_Urito Micro Controllers 3 29th April 2007 03:21 PM
Counter 555+ 4 bit binary counter psymon Electronic Projects Design/Ideas/Reviews 12 25th April 2007 08:51 AM
Query in 32 bit Parallel CRC...urgent pra.vlsi Electronic Projects Design/Ideas/Reviews 1 17th April 2007 12:46 PM
Need some help with a code provided by ATMEL ikalogic Micro Controllers 1 23rd January 2007 02:45 PM



All times are GMT. The time now is 12:02 PM.


Electronic Circuits  |  Electronics Wiki
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.