For the most part i can follow this code but i cant seem to grasp how the final 8-bits are constructed, see my comments below:
Original code web page see for more information
while(ir == 1);
INT0IE = 0;
while(ir == 0);
TMR0=0;
while(ir == 1);
i++;
dat[i]=TMR0;
if(dat[1] > 5000 && dat[1]<12000) ******Are 5000 and 12000 checking for <562uS or >2250uS, why only at dat[1]****
{
}
else
{
i=0;
INT0IE = 1;
}
if(i>=33)
{
GIE=0;
delay(50);
cmd=0;
for(j=26;j<34;j++)
{
if(dat[j]>1000 && dat[j]<2000) ****Not sure what 1000 and 2000 are, i know its the timer value but why these specific values to determine which way to shift*****
cmd<<=1;
else if(dat[j]>3500 && dat[j]<4500) ****same here*****
{
cmd|=0x01; ***I know this is an OR operator but it doesnt seem like it would change anything so what is its purpose here, for instance 1's will stay 1's and 0's will stay 0's but i have a feeling im just missing something***
cmd<<=1;
}
}
cmd>>=1; ****Why shift right here****
Any further understanding here will be great, thanks to anyone who will help.
I have been staring at this code example for 2 days trying to visualize how the data bits come in and then turned into only last 8-bits.
The implementation you are trying to analyze seems incomprehensible until you get some real understanding of how the NEC IR transport protocol works. See this link for the code I created.
See: Vishay IR protocols and NEC IR protocol WB_IRRC.
There are a lot of confusing, incomplete and just plain wrong descriptions of the NEC IR transport protocol to be found on the web. The comments in my code are not much better as they are there to remind me of what I was thinking when I created this mess.