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
}
}
}
}
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
- Popular Resources
- Popular amplifiers
- Wireless Sensor Network Technology and Applications (Edited by Mou Si, Yin Hong, and Su Xing)
- Modern Electronic Technology Training Course (Edited by Yao Youfeng)
- Modern arc welding power supply and its control
- Small AC Servo Motor Control Circuit Design (by Masaru Ishijima; translated by Xue Liang and Zhu Jianjun, by Masaru Ishijima, Xue Liang, and Zhu Jianjun)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- Innolux's intelligent steer-by-wire solution makes cars smarter and safer
- 8051 MCU - Parity Check
- How to efficiently balance the sensitivity of tactile sensing interfaces
- What should I do if the servo motor shakes? What causes the servo motor to shake quickly?
- 【Brushless Motor】Analysis of three-phase BLDC motor and sharing of two popular development boards
- Midea Industrial Technology's subsidiaries Clou Electronics and Hekang New Energy jointly appeared at the Munich Battery Energy Storage Exhibition and Solar Energy Exhibition
- Guoxin Sichen | Application of ferroelectric memory PB85RS2MC in power battery management, with a capacity of 2M
- Analysis of common faults of frequency converter
- In a head-on competition with Qualcomm, what kind of cockpit products has Intel come up with?
- Dalian Rongke's all-vanadium liquid flow battery energy storage equipment industrialization project has entered the sprint stage before production
- Allegro MicroSystems Introduces Advanced Magnetic and Inductive Position Sensing Solutions at Electronica 2024
- Car key in the left hand, liveness detection radar in the right hand, UWB is imperative for cars!
- After a decade of rapid development, domestic CIS has entered the market
- Aegis Dagger Battery + Thor EM-i Super Hybrid, Geely New Energy has thrown out two "king bombs"
- A brief discussion on functional safety - fault, error, and failure
- In the smart car 2.0 cycle, these core industry chains are facing major opportunities!
- The United States and Japan are developing new batteries. CATL faces challenges? How should China's new energy battery industry respond?
- Murata launches high-precision 6-axis inertial sensor for automobiles
- Ford patents pre-charge alarm to help save costs and respond to emergencies
- New real-time microcontroller system from Texas Instruments enables smarter processing in automotive and industrial applications
- CC2652LP driving Δ∑ ADC - ADS1261
- Toyota car machine disassembly suitable for DIY modification
- EEWORLD University Hall----Nonlinear Control Systems
- STM32 serial port baud rate calculation
- [Help] GD32 proteus simulation
- It’s too difficult for beginners.
- Help converting brd file to AD pcbdoc file
- Circuit Principle
- MSP430 interrupt priority and interrupt nesting
- A novice asks about the selection of optocouplers for PWM isolation control of MOS tubes