# Thread: Need help to understand what this function is doing

1. ## Need help to understand what this function is doing

Hello!
I'm new here and new at C. I am working off some example code and modifying it to suit my application.
I don't understand the example code even though I think it is basic.
I do not understand what |= means (line 5 of function)

Code:
void WriteByte (uchar DATA)
{
uchar RG = 0;
unit temp = 0xB800;
temp|=DATA;
if (RG = 0)
{
goto loop;
}
else
{
RG = 0;
}
}

void main()
uint ChkSum;
while (1)
{
ChkSum = 0;
WriteByte (0x30);
ChkSum+=0x30;
WriteByte (0x31);
ChkSum+=0x31;

WriteByte (0x32);
ChkSum+=0x32;
WriteByte (0x33);
ChkSum+=0x33;        // what does += mean?

ChkSum&=0xFF;        // what does &= mean?
WriteByte(ChkSum);
}
Any help is appreciated.
N_N

2. It is a bitwise OR to set a bit I believe.
so if it is
i=0;
i = 0|1
i becomes 1

3. Thank you!
What about the rest? What does += mean and &=?
And what is the code doing?
Thanks!
N_N

4. += ??
is the same as

n = n+1

&= bit wise..clears a bit

n=1
n = 1&0
n is now 0

for example

A is 65 0100 0001
to get that to be
i will clear bit 0 and set bit 2

char a = A
a&=0x01 ;
a|=0x02 ;

a is now B.
that should work..if it didn't well it is something like that..
and if it did, it should make things clearer..
and know I have no freaking idea what that code does...
you copied and paste from some random site huh?

5. Thanks-
Well no, it is not from some random site exactly
I am configuring a RFM12 transceiver to work with a PIC.
http://www.hoperf.com/upfile/RF12_code.pdf

There is some FSK protocol that I have no freakin idea about and how to transmit data wirelessly. That is what the code is doing- transmitting wireless data by accessing internal registers on the RFM12 chip.

So what I have copied and pasted is a little bit edited (I took out all the stuff that has nothing to do with transmitting). Also- it is from a different site than the pdf I posted, I found some sample code with comments.

It is hard for me to dissect sample code because I haven't done much C coding in the past few years.
N_N