Extracting BITs from BYTE

Status
Not open for further replies.
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:
hi C,
Look in Program File/Oshonsoft, compare the file dates and sizes, see if they are the same as mine, ref image.
E

 
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.
 
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.
 
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,
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.
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.
https://www.electro-tech-online.com...ceiving-using-scr-radio-modules.149198/page-7
Thanks, C.
 
Last edited:
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.
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…