• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Extracting BITs from BYTE

ericgibbs

Well-Known Member
Most Helpful Member
#22
hi C,
As you may know, when you power up your PIC, the memory area holding variables may or may not be cleared to zero.
[depending on whose compiler you are using]
So if you used 'x' as a indexing counter variable, it could be loaded with say 3 etc on power up.
So your increment would start at 3.
You can either
Dim x as a Byte ' then
x=0
or tick the pop up menu
I prefer to set variable values in the code.
E
 

camerart

Active Member
Thread starter #23
hi C,
As you may know, when you power up your PIC, the memory area holding variables may or may not be cleared to zero.
[depending on whose compiler you are using]
So if you used 'x' as a indexing counter variable, it could be loaded with say 3 etc on power up.
So your increment would start at 3.
You can either
Dim x as a Byte ' then
x=0
or tick the pop up menu
I prefer to set variable values in the code.
E
Hi E,
I didn't know about clearing variables, I'll try to remember to tick the box, Thanks.
My version doesn't show 'Initialise variable under the OPTIONS drop down?
C.
 
Last edited:

ericgibbs

Well-Known Member
Most Helpful Member
#24
hi C,
Look in Program File/Oshonsoft, compare the file dates and sizes, see if they are the same as mine, ref image.
E

A02.gif
 
#26
Morning E,
I understand that the > sign is greater than, but why did S mention it in this context? Unless he was mixing up the < in that section?
C.
Your picture of code with res1 and res2 were both comparing by > 0. That is why I said the ">" is irrelevant, you compare to 0 or 1 with an "=" instead to test the state of a bit.

I was referring to your original code, and trying to explain why I used "=" instead.
 

camerart

Active Member
Thread starter #27
Your picture of code with res1 and res2 were both comparing by > 0. That is why I said the ">" is irrelevant, you compare to 0 or 1 with an "=" instead to test the state of a bit.

I was referring to your original code, and trying to explain why I used "=" instead.
Hi S,
I see now! Thanks. I know the code I was following was written by an 'expert', so why would it be written like that? Written in 'C'
C.
 

Pommie

Well-Known Member
Most Helpful Member
#28
It is sometimes useful to use the greaterthan comparison operator when testing bits other than zero when the compiler doesn't support bit types. If(var & 4 > 0) will work where as if(var & 4 == 1) will not. However, it's clearer to use if(var & 4 == 0) or if(var & 4 != 0). You can also use if(var & 4 == 4) as well. Hope I didn't confuse the subject even more.

Mike.
 

camerart

Active Member
Thread starter #29
Hi,
Here's a slightly updated version of yesterdays program. BITS and BYTES
I am sure there are mistakes, feel free to point any out.
I now have to understand how the FIFO works, to finish the program.
C.
It is sometimes useful to use the greaterthan comparison operator when testing bits other than zero when the compiler doesn't support bit types. If(var & 4 > 0) will work where as if(var & 4 == 1) will not. However, it's clearer to use if(var & 4 == 0) or if(var & 4 != 0). You can also use if(var & 4 == 4) as well. Hope I didn't confuse the subject even more.

Mike.
Hi M,
I've just updated the full program using Sagor's code, which I will test. If it fails then please remind me and I'll try your suggestion.
http://www.electro-tech-online.com/...ceiving-using-scr-radio-modules.149198/page-7
Thanks, C.
 
Last edited:

Pommie

Well-Known Member
Most Helpful Member
#30
As I said, it's only useful if the compiler doesn't support the bit type. Yours does so just use the equals operator.

Mike.
 

Latest threads

EE World Online Articles

Loading

 
Top