Infrared remote sensing

https://blog.csdn.net/lightrour/article/details/79485040 After
reading the above article, I will describe the overall process myself:

  1. Every time a button is pressed, the infrared will send a sequence of high and low levels, and then decode it according to the stipulated protocol NEC.
  2. There are three situations in the timing sequence, that is, the high level time has the following situations: 4.5ms (pilot signal), 1680us (logic 1), 560us (logic 0), 2.5ms (the number of keystrokes increases automatically), 97.94ms (continuous signalling) )
  3. The general process of the program, and some flag bits:
    when the input capture detects the pilot signal (high level 4.5ms), set the flag bit RmtSta|=1<<7, which means that the start signal is received, and then the subsequent ones can be detected The high level time of the pulse is decoded into logic 1 or logic 0, (if (RmtSta&0X10) is followed by the decoding process).
    4. When the program is configured with two interrupts in the interrupt function, one is the update interrupt, the other is the capture interrupt (rising edge and falling edge), and the high level time detection is also done by capturing (described above), Because the priority of these two interrupts is the same, there will be no interruption, but if the high level exceeds 10ms (auto-load value), an overflow interrupt will occur. At this time, there are two situations where the high level time exceeds 10ms:
    1). It is 97.94ms to send the signal continuously. At this time, the transmission frame of a key press has been transmitted, so you can set a key value to collect information, RmtSta|=1<<6;, and turn off the rising edge Capture mark RmtSta&=~0X10; (because there is no need to calculate the capture high level time here) and then the subsequent pulse sequence has a high level of 2.5ms, because the sign of the start of the boot has not been shielded at this time, so the capture can also be detected For the height of the level, we use the number of high levels of 2.5ms to calculate the number of key presses.
    2) But there is another situation where the button is completely released, this time it will always be high, then start counting, so the high level time will be recorded in the overflow interrupt, if this judgment is satisfied if((RmtSta&0X0F )<14)RmtSta++, it means that the high level can be judged as the button is released, we will turn off the flat sign of the guiding point.

Guess you like

Origin blog.csdn.net/weixin_42595206/article/details/103603336