1. Introduction
Infrared transmitter module: Power supply 3.3V or 5V, transmits 38KHz infrared signal through the transmitter tube, high level drive
Infrared receiving module: Power supply 3.3V or 5V, can receive infrared signals and demodulate them into logic levels, low level is effective
2. Circuit Diagram
Infrared transmitter circuit diagram
Infrared receiving circuit diagram
3. Infrared transmitter module code
#include
#include
#define uchar unsigned char
#define uint unsigned int
//Pin definition
sbit key = P2^0;
sbit out = P2^1;
// Function declaration
void delayms(uchar aa); //Infrared emission delay
void khz(uchar aa); //Transmit 38KHz
void IR_OUT(uchar num); //infrared emission
void keyScan(); //Read keyboard information
//Variable declaration
fly i, a, num1;
//-----------------------
//Infrared emission delay
//-----------------------
void delays(fly aa)
{
for(a=aa; a>0; a--)
{
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
_nop_();
}
}
//-----------------------
//Transmit 38KHz
//-----------------------
void khz(uchar aa)
{
for(a=aa;a>0;a--) //This for statement can get the accurate 26.3 baud rate
{
out=0;
i=7;
while(i>0) i--; //38kHZ
out=1;
}
}
//-----------------------
//Infrared emission
//-----------------------
void IR_OUT(uchar num)
{
khz(116); //transmit 3ms 38khz
delayms(125);
for(num1=8; num1>0; num1--)
{
khz(40);
if(num&0x01)
delayms(93); //delay 1.5ms
else
delayms(65); //delay 1ms
num=num>>1;
}
khz(20);
}
//-----------------------
//Read keyboard information
//-----------------------
void keyScan()
{
if(key==0)
{
_nop_(); _nop_(); _nop_();
_nop_(); _nop_(); _nop_();
if(key==0)
IR_OUT(0xC0);
key = 1;
}
}
//-----------------------
//Main function
//-----------------------
void main()
{
key = 1;
while(1)
{
keyScan();
}
}
4. Infrared receiving module code
#include
#include
#define uchar unsigned char
#define uint unsigned int
//Pin definition
sbit in = P3^2; //Infrared interrupt reception
//P2 connects to static digital tube
// Function declaration
void init(); //initialization function
void delayms(uchar j); //delay function
//Variable declaration
fly i, num, a;
bit fleg;
//-----------------------
// Initialization function
//-----------------------
void init()
{
fleg = 1; //flag
in = 1; //infrared receiving
EA = 1; //Interrupt setting
EX0 = 1;
IT0 = 1;
}
//-----------------------
//Delay function
//-----------------------
void delays(fly j)
{
for(i=j; i>0; i--)
{
_nop_(); _nop_(); _nop_();
_nop_(); _nop_(); _nop_();
}
}//-----------------------
//Main function
//-----------------------
void main()
{
heat();
while(1);
}
//-----------------------
//Receive interrupt
//-----------------------
void sieasdf() interrupt 0
{
EX0 = 0;
for(a=5; a>0; a--)
{
delayms(35); //delay 0.5ms, judge 5 times 5*0.5=2.5ms
if(in) fleg=0;
}
if(fleg)
{
delayms(72); // Delay 1ms to determine whether it is a high level
if(in)
{
delayms(115); //delay to make it longer than 2ms; 2.5+1+1.623=5.123ms to start reading data
delayms(118); //If it is offset by one bit, it can be removed.
for(a=8; a>0; a--)
{
while(!in);
delayms(86); //Delay 1.188ms to judge IO high or low, and get 0 or 1
num = num>>1;
if(in)
{
num = num|0x80;
delayms(31); // Delay 0.6ms because the delay above is 1.2ms+0.6, just skipping 1.5ms
}
}
P2 = whether;
}
}
flag = 1;
EX0 = 1;
}
Previous article:「51 MCU」Basic usage of Bluetooth slave
Next article:「51 single chip microcomputer」transmitter and receiver ultrasonic ranging module analysis + code
- Popular Resources
- Popular amplifiers
- Learn ARM development(16)
- Learn ARM development(17)
- Learn ARM development(18)
- Embedded system debugging simulation tool
- A small question that has been bothering me recently has finally been solved~~
- Learn ARM development (1)
- Learn ARM development (2)
- Learn ARM development (4)
- Learn ARM development (6)
Professor at Beihang University, dedicated to promoting microcontrollers and embedded systems for over 20 years.
- LED chemical incompatibility test to see which chemicals LEDs can be used with
- Application of ARM9 hardware coprocessor on WinCE embedded motherboard
- What are the key points for selecting rotor flowmeter?
- LM317 high power charger circuit
- A brief analysis of Embest's application and development of embedded medical devices
- Single-phase RC protection circuit
- stm32 PVD programmable voltage monitor
- Introduction and measurement of edge trigger and level trigger of 51 single chip microcomputer
- Improved design of Linux system software shell protection technology
- What to do if the ABB robot protection device stops
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- From probes to power supplies, Tektronix is leading the way in comprehensive innovation in power electronics testing
- Sn-doped CuO nanostructure-based ethanol gas sensor for real-time drunk driving detection in vehicles
- Design considerations for automotive battery wiring harness
- Do you know all the various motors commonly used in automotive electronics?
- What are the functions of the Internet of Vehicles? What are the uses and benefits of the Internet of Vehicles?
- Power Inverter - A critical safety system for electric vehicles
- Analysis of the information security mechanism of AUTOSAR, the automotive embedded software framework
- Brief Analysis of Automotive Ethernet Test Content and Test Methods
- How haptic technology can enhance driving safety
- Showing goods + Embedded Primary Development Board (MOOC) video
- Altium Designer v20.1.12.249
- Thank you for being my first leader in the workplace
- MicroPython now supports STM32L452
- MOS tube control shutdown problem
- MicroPython Hands-on (06) - Learn MaixPy monocular camera from scratch
- Goodbye 2019, Hello 2020 + Review of my 2019
- MSP430 non-continuous IO parallel port output matrix keyboard
- Zero environment setup, the simplest QT interface programming Helloworld runs in the embedded Linux touch industrial tablet
- Share: STM32 controls HC-05 Bluetooth module for communication