NEC protocol for infrared Protocol

Source: Internet
Author: User

NEC protocol for infrared Protocol

NEC protocol carrier: 38 khz

The representation of logic 1 and logic 0:

The logic 1 is 2.25 ms, the pulse time is 1.12 us, the logic 0 is ms, and the pulse time is us. Therefore, we decode the time based on the pulse length. The recommended carrier duty cycle is 1/3 to 1/4.

NEC protocol format:

The first sending is a 9 ms High-Level Pulse, followed by a 4.5ms low-level pulse, followed by an 8-bit address code (starting from the low-effective bit ), then there is an 8-bit reverse code of the address code (mainly used to verify whether an error occurs ). Then the 8-bit command code (also starting from the low valid bit) is sent, and then the 8-bit command code is reversed.

The above is a normal sequence, but there may be a situation: you keep pressing a key, in this case, send a recurring code with a cycle of MS, such:

That is to say, after a command code is sent, the command code will not be sent again, but will be sent at intervals of 110ms.

The repeat code consists of a 9 ms high level and a Ms low level and a 560us high level.

Note that the 1838 infrared integrated receiving head is used to increase the sensitivity of the receiver. The input is high, and the output is the opposite low.

After an afternoon and evening, NEC decoded the code and made some minor mistakes. After a long time, I did not get any results. A little depressed. This morning, I looked at others' reference code carefully. I was suddenly impressed by the following small details.

Note the following code:

Void hal_NEC_decode (uchar * addr, uchar * addrt, uchar * comm, uchar * commt)
{
Uchar I, j, k;
Uchar tmp1 = 0;

While (NECFinshFlag = 0 );
NECFinshFlag = 0;

For (I = 0, k = 1; I <4; I = I + 1)
{
For (j = 1; j <= 8; j ++)
{
If (NECTimerTable [k ++]> 7)
{
Tmp1 | = 0x80;
}
Tmp1> = 1;
}
Switch (I)
{
Case 0: * addr = tmp1; break;
Case 1: * addrt = tmp1; break;
Case 2: * comm = tmp1; break;
Case 3: * commt = tmp1; break;
}
Tmp1 = 0;
}
}

At last, the value of tmp1 is shifted to one place on the right. So change the code

Void hal_NEC_decode (uchar * addr, uchar * addrt, uchar * comm, uchar * commt)
{
Uchar I, j, k;
Uchar tmp1;

While (NECFrameFlag = 0 );
NECFrameFlag = 0;

For (I = 0, k = 1; I <4; I = I + 1)
{
Tmp1 = 0;
For (j = 0; j <8; j ++)
{
Tmp1> = 1; // shift one digit to the right in advance to prevent the last loop from error
If (NECTimerTable [k ++]> 8)
{
Tmp1 | = 0x80;
}
}
Switch (I)
{
Case 0: * addr = tmp1; break;
Case 1: * addrt = tmp1; break;
Case 2: * comm = tmp1; break;
Case 3: * commt = tmp1; break;
}
}
}

After modifying the code sequence, the program can parse the NEC protocol perfectly. It can be seen that writing a program is also very important, and may involve the entire success.

Conclusion: in the future, write a program that consists of 1 bit (starting from LSB or MSB) to receive a byte. Pay special attention to the shift left or right of the loop. Implement moving the temporary variable to avoid errors caused by moving the last bit.

Next, we will attach the command code of the NEC protocol (commonly used remote control board on the market)

This article permanently updates the link address:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.