void IR_IN() interrupt 0 using 0 //Using 12MHz crystal
{
unsigned char j,k,N=0;
EX0 = 0; // Initialize, turn off external interrupt
delay(15);
if (IRIN==1) //no pulse arrives high level
{ EX0 =1; //Enable interrupt in default state, look for 9ms boot pulse
return;
}
//Confirm that the IR signal appears
while (!IRIN) //Wait for IR to become high level and skip the 9ms leading low level signal.
{delay(1);} //The MCU receiving level is completely opposite to the remote control level, delay(1) delay 0.14ms
for (j=0;j<4;j++) //Collect four sets of data
{
for (k=0;k<8;k++) //Each set of data has 8 bits
{
while (IRIN) //Wait for IR to become low level and skip the 4.5ms leading high level signal.
{delay(1);}
while (!IRIN) //Wait for IR to become high level (0.56ms)
{delay(1);}
while (IRIN) //Calculate the duration of IR high level
{
delay(1);
N++;
if (N>=14) //Greater than 1.685ms high level length, in order to ensure reliability N=14
{ EX0=1; //(2.25/0.14=16,1.685/0.14=12,0.565/0.14=4)
return;} //0.14ms count is too long, automatically exit, re-judge.
} //High level counting completed
IRCOM[j]=IRCOM[j] >> 1; //Fill the highest bit of data with "0"
if (N>=6) {IRCOM[j] = IRCOM[j] | 0x80;} //High level length greater than 0.565ms, N=6, 7, 8 (1.685/2) are all OK, judged as "1", the highest bit of the data is filled with "1"
N=0;
}//end for k
}//end for j
if (IRCOM[2]!=~IRCOM[3]) The data code is opposite to the data inverse code, continue to execute, otherwise, the data is wrong. Return and re-judge.
{ EX0=1;
return; }
IRCOM[5]=IRCOM[2] & 0x0F; //Get the lower four bits of the key code
IRCOM[6]=IRCOM[2] >> 4; // Shift right 4 times, the upper four bits become the lower four bits
if(IRCOM[5]>9)
{ IRCOM[5]=IRCOM[5]+0x37;} //Convert to the corresponding ASCII code and send to 1602 for display.
else
IRCOM[5]=IRCOM[5]+0x30;
if(IRCOM[6]>9)
{ IRCOM[6]=IRCOM[6]+0x37;}
else
IRCOM[6]=IRCOM[6]+0x30;
lcd_pos(0x4b);
lcd_wdat(IRCOM[6]); //First digit display
lcd_pos(0x4c);
lcd_wdat(IRCOM[5]); //The second digit is displayed
beep();
EX0 = 1; //Open interrupt and continue judging
}
Previous article:Microcontroller as infrared remote control decoder
Next article:Electronic clock based on single chip microcomputer, DS1302 and DS1602
Recommended Content
Latest Microcontroller Articles
- Naxin Micro and Xinxian jointly launched the NS800RT series of real-time control MCUs
- How to learn embedded systems based on ARM platform
- Summary of jffs2_scan_eraseblock issues
- Application of SPCOMM Control in Serial Communication of Delphi7.0
- Using TComm component to realize serial communication in Delphi environment
- Bar chart code for embedded development practices
- Embedded Development Learning (10)
- Embedded Development Learning (8)
- Embedded Development Learning (6)
He Limin Column
Microcontroller and Embedded Systems Bible
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
MoreSelected Circuit Diagrams
MorePopular Articles
- Intel promotes AI with multi-dimensional efforts in technology, application, and ecology
- ChinaJoy Qualcomm Snapdragon Theme Pavilion takes you to experience the new changes in digital entertainment in the 5G era
- Infineon's latest generation IGBT technology platform enables precise control of speed and position
- Two test methods for LED lighting life
- Don't Let Lightning Induced Surges Scare You
- Application of brushless motor controller ML4425/4426
- Easy identification of LED power supply quality
- World's first integrated photovoltaic solar system completed in Israel
- Sliding window mean filter for avr microcontroller AD conversion
- What does call mean in the detailed explanation of ABB robot programming instructions?
MoreDaily News
- STMicroelectronics discloses its 2027-2028 financial model and path to achieve its 2030 goals
- 2024 China Automotive Charging and Battery Swapping Ecosystem Conference held in Taiyuan
- State-owned enterprises team up to invest in solid-state battery giant
- The evolution of electronic and electrical architecture is accelerating
- The first! National Automotive Chip Quality Inspection Center established
- BYD releases self-developed automotive chip using 4nm process, with a running score of up to 1.15 million
- GEODNET launches GEO-PULSE, a car GPS navigation device
- Should Chinese car companies develop their own high-computing chips?
- Infineon and Siemens combine embedded automotive software platform with microcontrollers to provide the necessary functions for next-generation SDVs
- Continental launches invisible biometric sensor display to monitor passengers' vital signs
Guess you like
- How to Get Rid of Electromagnetic Interference in the Process of Single Chip Microcomputer Design
- 【NXP Rapid IoT Review】+ Trial Computer Programming & Mobile Phone Control
- TMS320C6747 Fixed-point/Floating-point Digital Signal Processor
- Chip Manufacturing 7-Chip Manufacturing
- FPGA water lamp design vhdl source program
- USB packet capture module protocol
- Application Tips/Low Power Design in 80C51 Portable Products
- Analog Electronics Basic Circuit Collection 35/90
- The PWM wave output of TL494 in the boost circuit is abnormal. Please help me
- About the problem of AGND and DGND of microcontroller