Take a look at the two snippets of code below. It was written for an 8051 micro-controller.
void main (void)
{
unsigned int a,i;
a=11;
for(i=0;i=8;i++)
{
If ((a>i)&0x1==1)
{
delay();
}
}
}
My question with regards to the above section of code are:
1.What does the IF condition in this code do? I don’t understand it. According to the person who wrote this code, the condition compares to see if each bit of a = 1/0. If it is a 1, then the delay function is called. How does this comparison work??????
2.Can this exact same if condition be used as it is on the PIC uController without any syntax change?
Here is the second piece of code again written for a 8051 uController
void main (void)
{
unsigned int a=0,i;
for(i=0;i=4;i++)
{
if (P1_1=0) //if a port is low
{
a=a|1<<i;
}
}
}
1.What does a=a|1<<i do? And how does it function?
2.Lets say when i=0,1,2,3,4 , P1_1=0. What would the value of a be in this case?
3.If P1_1=0 when i=0,1,2 and 4 but at i=3 this condition is false. What is the value of a in this case?
4.Can this line of code be used just as it is for the PIC uController (i mean with regards to syntax)?
Really looking forward to hearing from everyone
reenalalu
void main (void)
{
unsigned int a,i;
a=11;
for(i=0;i=8;i++)
{
If ((a>i)&0x1==1)
{
delay();
}
}
}
My question with regards to the above section of code are:
1.What does the IF condition in this code do? I don’t understand it. According to the person who wrote this code, the condition compares to see if each bit of a = 1/0. If it is a 1, then the delay function is called. How does this comparison work??????
2.Can this exact same if condition be used as it is on the PIC uController without any syntax change?
Here is the second piece of code again written for a 8051 uController
void main (void)
{
unsigned int a=0,i;
for(i=0;i=4;i++)
{
if (P1_1=0) //if a port is low
{
a=a|1<<i;
}
}
}
1.What does a=a|1<<i do? And how does it function?
2.Lets say when i=0,1,2,3,4 , P1_1=0. What would the value of a be in this case?
3.If P1_1=0 when i=0,1,2 and 4 but at i=3 this condition is false. What is the value of a in this case?
4.Can this line of code be used just as it is for the PIC uController (i mean with regards to syntax)?
Really looking forward to hearing from everyone
reenalalu