Coding/decoding and recognition driver for infrared remote control
Because the encoding formats of different remote control may be different, here is only the single-chip computer recognition program of this remote control I currently use and the method that can decode the infrared remote control with unknown encoding formats.
The infrared remote control code is generally composed of the guiding code, system code, system code, function code, function code, fixed stop code, or verification code.
1. The example remote control decoding and recognition program is used as an example. The remote control belongs to the encoding of an air conditioner remote control. (In the future, T refers to the time of us)
The encoding format consists of the boot code, Fixed Header code, function code, and verification code.
The Guide Code Pulse is 8 TB of high voltage and 8 TB of low level.
Bit 1 pulse width is 1 t of the high level, 3 t of the low level.
Bit 0 pulse width is 1 t of the high level, 1 t of the low level.
The verification code is used to retrieve all data except rdrv_pulsewidth and accumulate inverse values.
Shows the waveform of infrared remote control:
I used the timer 1 in the microcontroller and the interrupt corresponding to the infrared receiving head. The interrupt uses the descent edge, mainly through the pulse low-level time.
Different to distinguish different data. The timer 1 is used to calculate the interval between two consecutive interruptions (corresponding to the pulse width)
According to the above conditions, the infrared remote control recognition program is written as follows:
# Include "public. H "# define periodt 25 // t time/16us static 2010oldt1count = 0; // save the old counter value of counter 1 static 2010t1count = 0; // Save the current value of counter 1 static u8 bitcount = 0; // write bit value static u8 newdata; // is there a new frame of Data arrival mark u8 recvdata [12]; // The array used to save the received data static u8pulsewidth = 0; // calculated pulse width value /******************************* **************************************** * ****** // function: vdrv_exitintpc4init () // Description: An External Interrupt of the infrared key pc4 // Author: huangzhigang 2014-0306 ************************************ **************************************** * **/void vdrv_exitintpc4init () {// pc4 interrupt input floating gpio_init (gpioc, gpio_pin_4, gpio_mode_in_fl_it); // IO port corresponding to the infrared receiver // exti_setextintsensitioc (exti_port_gpioc, callback ); // The rising edge triggers the interrupt exti_setextintsensitioc (exti_port_gpioc, exti_sensitivity_fall_only); // The falling edge triggers the interrupt }/***************** **************************************** * ********************* // Function: timestamps Init () // Description: timer 1 Initialization Configuration // Author: huangzhigang 2014-0306 ************************************ **************************************** * **/void timestamps Init () {timeredeinit (); // The Counter-up frequency is 256. The auto-Reload value is 0 xFFFF // 256/16 = The 16us counter is added once to 0 xFFFF for clearing and then timeretimebaseinit (255, timerecountermode_up, 0 xFFFF, 0); // update interruption allowed // timereitc Onfig (timereit_update, enable); timerecmd (enable );} /*************************************** **************************************** // function: rdrv_pulsewidth // Description: calculated pulse width // Param: // return: returns 1 with a width. returns 0 with an invalid width. // others: // Author: huangzhigang 2014-0306 ************************************ **************************************** * **/u8 rdrv_pulsewidth () // u8 * pulsewidth {t1count = timeregetcounter (); If (oldt1count = 0) {oldt1count = t1count; u8pulsewidth = 0; return 0;} else {If (t1count-oldt1count> 0) {u8pulsewidth = T1Count-OldT1Count; oldt1count = t1count; return 1;} else {u8pulsewidth = 0xffff-oldt1count + t1count; oldt1count = t1count; return 1 ;}}} /*************************************** **************************************** // function: vdrv_writerecvdata // Description: Data writing array // Param: whether the value written by u8bit is 1 or 0. When the remote control sends data, the system first sends high data and then sends low data. // Author: huangzhigang 2014-0306 ************************************ **************************************** * **/void vdrv_writerecvdata (u8 u8bit) {u8 bit = 1; if (u8bit) {recvdata [bitcount/8] | = bit <(7-(bitcount % 8 )); // write 1} else {recvdata [bitcount/8 ~ (Bit <(7-(bitcount % 8); // the corresponding bit writes 0} If (++ bitcount> 95) {newdata = 0; bitcount = 0 ;}} /*************************************** **************************************** // function: interrupt_remote // Description: Infrared Remote Control pc4 Interrupt Processing // train of thought: there is a remote control waveform to calculate the entry condition, 1, 0 pulse width of each situation // The entry condition: for 8 t low voltage and 8 t high level below the descent line for the trigger mode timing 16 t/1: 1 t Low Level 3 t high level timing 4 t // 0; 1 TB Low Level 1 TB High Level timing 2 TB // calculation method timer 1 Timing 16us T = 400us so the 1 TB time equals counter plus 400/16 = 25 times/16 t = 26*16 = 400 4 T = 100 2 T = 50 // Author: huangzhigang 2014-0306 ************************************ **************************************** * **/void interrupt_remote () {If (rdrv_pulsewidth () {If (u8pulsewidth >=( 400-5) & (u8pulsewidth <= (400 + 5 ))) // periodt * 16 + herror // 5 indicates the error range {newdata = 1; // indicates that the array write function is enabled when new data arrives.} else if (u8pulsewidth >=( 100-5) & (u8pulsewidth <= (100 + 5 )) & (newdata = 1) {vdrv_writerecvdata (1);} else if (u8pulsewidth >=( 50-5 )) & (u8pulsewidth <= (50 + 5) & (newdata = 1) {vdrv_writerecvdata (0);} else {newdata = 0; bitcount = 0 ;}}}
2. How to crack the infrared remote control with unknown encoding. I am using the single-chip microcomputer. The powerful debugging function of the St downloader allows me to monitor the operation and variable changes of the single-chip microcomputer program in real time.
All the functions except rdrv_pulsewidth () in the above Code interrupt_remote () are removed, because the actual coding and pulse width of the infrared remote control are unknown. Use an array to record and save the pulse width calculated by the rdrv_pulsewidth () function after each interruption. (It is recommended that the array be large enough, usually dozens of bytes, if you do not know ). In this way, after an infrared remote control button, we can obtain a complete set of pulse width data in the array we set. We can identify the encoding of the remote control from this set of data, and you can use it in your own Microcontroller program (code will be added later ).
Infrared Remote Control-encoding/decoding and recognition driver for infrared remote control