New explanation of the source code of the MCU infrared remote control decoding routine

Publisher:美人如玉剑如虹Latest update time:2015-09-21 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere
This is the third time that I have changed the infrared remote control decoding routine. The first version used the external interrupt of the 51 microcontroller directly and then added a delay to collect the length of the high and low levels to determine the boot code and bit 1 and bit 0. I don't know where I saw this at the beginning. This method is too misleading. If you want to use this idea to transplant it to stm32, you should stop as soon as possible. Is this advanced processor like stm32 only used for infrared remote control decoding? No, there will definitely be more advanced tasks waiting for it to process. External interrupt plus delay can improve the response speed of the remote control, but in fact this method is very resource-intensive. When the cpu is processing other urgent tasks, a key suddenly comes to interrupt the process and occupy the process. After testing, a key code of the remote control takes 50-90ms, which is not a small time for the microcontroller. Therefore, the external interrupt + timer can be combined for decoding.
The external interrupt turns on the rising and falling edges to trigger at the same time. In this way, after two triggers, we calculate the high or low comment time to see if it is accurate.
The state machine, that is, the state change idea, can be used for decoding. The boot code and user code are divided into two parts for decoding. The high level and low level are divided into two parts for decoding.
Because the difference between bit 1 and bit 0 is the different time of high level, that is, bit 0 _|—| bit 1
  _|——| The time of low level of both
is the same, and the high level behind is long for 1 and short for 0. This feature makes it particularly easy to solve. Please refer to the previous article, http://www.xiaovdiy.cn/?post=138
Source code is provided
         if(EXTI_GetITStatus(EXTI_Line12)!= RESET)
         {
          if(RDATA()==0)//Indicates that a falling edge has arrived
          {
           
        TIM_Cmd(TIM4, ENABLE);
                 if(lead_flg==0)//Indicates that it is the first time to receive the lead code
                 {
                            TIM_SetCounter(TIM4,0);//TIM4->CNT=0; (1)
            lead_flg=1;
                   }
                   else if(lead_flg==2)
                   {
                 ir_cnt= TIM_GetCounter(TIM4);    
            TIM_SetCounter(TIM4,0);
                            lead_flg=3;
                            if((ir_cnt<70)||(ir_cnt>90))//The test shows that it is 79 or 80
                            {
                              lead_flg=0; //Out of range, exit
              return 0;
              
                            }
                   }
                   else if(lead_flg==3)//Get the high level time
                   {
                            ir_cnt= TIM_GetCounter(TIM4);    
                            TIM_SetCounter(TIM4,0);
                            //Receive 3 bytes 24-bit code
                high_cnt++;//Add to 24 bits, 1 byte every 8 timesif
                     (high_cnt<=8)
                                     {
                                               user_code[0]>>=1;
                                     }
                if(high_cnt<=16)
                                     {
                                               user_code[1]>>=1;
                                               }
                if(high_cnt<=24)
                                     {
                                               user_code[2]>>=1;
                                     }
                     if((ir_cnt>35)&&(ir_cnt<45))//We think it is bit '1'
                                     {
                         if(high_cnt<=8)
                                               {
                                                        user_code[0]|=0x80;
 
                                               }
                    if(high_cnt<=16)
                                               {
                                                        user_code[1]|=0x80;
                                               }
                    if(high_cnt<=24)
                                               {
                                                        user_code[2]|=0x80;}
                                         }
                           if(high_cnt>24)//Acceptance completed
                                     {
                                               lead_flg = 0;
                                               high_cnt = 0;
                                               REM_FLG = 1;//Acquisition completed, clear flag
 
                                               TIM_Cmd( TIM4,DISABLE);
                                     }
                          
 
                   }
 
          }
          else if(RDATA()!=0)//It means that this is the first time to receive the high level of the lead code
          {
       if(lead_flg==0)
       {
       return 0;
       }
       else if(lead_flg==1)//We only need to accept one low level 2
            {
                            ir_cnt= TIM_GetCounter(TIM4);
                            TIM_SetCounter(TIM4,0);
                                     lead_flg=2;
                            if((ir_cnt<70)||(ir_cnt>90))
                            {
                              lead_flg=0;//Not what we want, exit
              return 0;
               
                            }
 
                   }
                   else if(lead_flg==3)//Non-lead code entry interrupt rising edge triggered
                   {  
                       ir_cnt= TIM_GetCounter(TIM4);
                            TIM_SetCounter(TIM4,0);
                                    
                            if((ir_cnt<8)||(ir_cnt>20))//Test data is ir_cnt =9 10 stable value
                            {
                              lead_flg=0;
              return 0;//Not what we want, exit
               
                            }
                           
 
                   }
          }
 
         }
Keywords:MCU Reference address:New explanation of the source code of the MCU infrared remote control decoding routine

Previous article:How to use the interrupt and counter of stm32 to capture the level duration of rising and falling edges
Next article:How to write data to the flash of stm32 and use it as eerom

Recommended ReadingLatest update time:2024-11-16 20:26

2023, raging automotive MCU
"Traditional cars use about 70 units per vehicle, while electric vehicles use about 300 units per vehicle." "Standing at the center of the chip shortage storm." “When there is a price increase due to core shortages, the price of some models increases by dozens of times, and tens of dollars turn into thousands of d
[Automotive Electronics]
2023, raging automotive MCU
Design of 51 single chip microcomputer and A/D interface
     The A/D converter is used to realize the conversion from analog to digital quantity. According to the conversion principle, it can be divided into four types, namely: counting A/D converter, dual-integral A/D converter, successive approximation A/D converter and parallel A/D converter.     The most commonly used
[Microcontroller]
Design of 51 single chip microcomputer and A/D interface
Detailed explanation of the microcontroller's instruction execution process
Detailed explanation of the microcontroller's instruction execution process The process of microcontroller executing a program is actually the process of executing the program we compiled. That is, the process of executing one instruction at a time. The computer can be divided into three stages for each instruction ex
[Microcontroller]
Detailed explanation of the microcontroller's instruction execution process
Getting Started with PIC Microcontrollers_MPLAB Integrated Development Environment and MPASM Compiler
1. Seven major assembly instructions 1.1 #INCLUDE Syntax: #include "filename.*" or filename.* or no brackets or quotes Example: #INCLUDE p12f675.inc 1.2 #DEFINE Used to define variables and assign initial values; user-friendly names are assigned to constants, registers, pin names, etc. to make the program easy to re
[Microcontroller]
Getting Started with PIC Microcontrollers_MPLAB Integrated Development Environment and MPASM Compiler
Design of automatic spinning yarn breakage detection system based on AT89C2051 microcontroller
introduction During the winding process of the spinning machine, it is very important to determine whether the thin thread is broken. Therefore, the spinning breakage detection device is a product that emerged based on actual needs. It can detect and monitor the spinning process. This article designs a multifunctional
[Microcontroller]
Design of automatic spinning yarn breakage detection system based on AT89C2051 microcontroller
51 MCU special function register and bit definition
In the next few sections, we will show you how to write your first MCU program. Before that, let's first understand some of the 51 MCU's unique program syntax and the basic operating steps of Keil software. Please be patient. We mainly use C language to program the MCU, and some MCU have a few very special and unique
[Microcontroller]
51 MCU special function register and bit definition
Design of LED running water lamp controlled by microcontroller
1 Introduction Today is an era in which new technologies are emerging one after another. In the electronic field, especially in the field of automated intelligent control, traditional control systems composed of discrete components or digital logic circuits are being replaced by single-chip intelligent control systems
[Microcontroller]
Design of low power consumption methane detection system based on 51 single chip microcomputer
1 Introduction Gas detection system is an essential safety equipment in industrial and mining enterprises, social utilities, environmental protection and other fields. After decades of development, the main technical indicators such as the types of measurable gases, measurement range, accuracy, stability, life,
[Microcontroller]
Design of low power consumption methane detection system based on 51 single chip microcomputer
Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号