The main content of this document details the information and source code of using the AT89S51 microcontroller to make an infrared remote control.
Generally, the output of an infrared TV remote control is generated by pulse amplitude modulation of a 38-40kHz square wave using encoded serial data.
When the transmitter button is pressed, a remote control code will be sent out. The remote control code will be different depending on the button pressed. This remote control code has the following characteristics:
Using pulse width modulation serial code, the combination of pulse width 0.565ms, interval 0.56ms, and period 1.125ms represents binary "0"; the combination of pulse width 0.565ms, interval 1.685ms, and period 2.25ms Represents binary "1".
The 32-bit binary code composed of the above "0" and "1" is modulated twice by the carrier frequency of 38kHz, and then the infrared ray is generated by the infrared emitting diode and emitted into space. The remote control code of a general TV remote control is a continuous 32-bit binary code group, of which the first 16 bits are the user identification code, which can distinguish different infrared remote control devices and prevent the remote control codes of different models from interfering with each other. The last 16 bits are the 8-bit operation code and the 8-bit operation complement code, which are used to check whether the data is received accurately.
According to the format of infrared encoding, a 9ms start code and a 4.5ms result code need to be sent before sending data.
The receiver generally uses the TL0038 integrated infrared receiver for reception and decoding. When the TL0038 receives a 38kHz infrared signal, the output terminal outputs a low level, otherwise it is a high level. Therefore, when the infrared remote control sends an infrared signal, refer to the remote control serial data encoding waveform diagram above. It sends a 38kHz infrared signal at a low level and does not send an infrared signal at a high level.
C51 program code:
#include "AT89X51.h"
static bit OP; //On and off of infrared emission tube
static unsigned int count; //delay counter
static unsigned int endcount; //termination delay count
static unsigned char flag; //Infrared sending flag
char iraddr1; //The first byte of the sixteen-bit address
char iraddr2; //The second byte of the sixteen-bit address
void SendIRdata(char p_irdata);
void delay();
void main(void)
{
count = 0;
flag = 0;
OP = 0;
P3_4 = 0;
EA = 1; //Allow CPU interrupt
TMOD = 0x11; //Set timers 0 and 1 to 16-bit mode 1
ET0 = 1; //Timer 0 interrupt enabled
TH0 = 0xFF;
TL0 = 0xE6; //Set the time value 0 to 38K, which means interrupting every 26us
TR0 = 1;//Start counting
iraddr1=3;
iraddr2=252;
do{
delay();
SendIRdata(12);
}while(1);
}
//Timer 0 interrupt processing
void timeint(void) interrupt 1
{
TH0=0xFF;
TL0=0xE6; //Set the time value to 38K, which means interrupting every 26us
count++;
if (flag==1)
{
OP=~OP;
}
else
{
OP = 0;
}
P3_4 = OP;
}
void SendIRdata(char p_irdata)
{
int i;
char irdata=p_irdata;
//Send 9ms start code
endcount=223;
flag=1;
count=0;
do{}while(count《endcount);
//Send 4.5ms result code
endcount=117
flag=0;
count=0;
do{}while(count《endcount);
//Send the first eight digits of the sixteen-digit address
irdata=iraddr1;
for(i=0;i《8;i++)
{
//First send 0.56ms 38KHZ infrared wave (i.e. 0.56ms low level in encoding)
endcount=10;
flag=1;
count=0;
do{}while(count《endcount);
//Stop sending infrared signals (i.e. high level in encoding)
if(irdata-(irdata/2)*2) //Determine whether the binary number is 1 or 0
{
endcount=41; //1 is the wide high level
}
else
{
endcount=15; //0 is a narrow high level
}
flag=0;
count=0;
do{}while(count《endcount);
irdata=irdata》》1;
}
//Send the last eight digits of the sixteen-digit address
irdata=iraddr2;
for(i=0;i《8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count《endcount);
if(irdata-(irdata/2)*2)
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count《endcount);
irdata=irdata》》1;
}
//Send eight bits of data
irdata=p_irdata;
for(i=0;i《8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count《endcount);
if(irdata-(irdata/2)*2)
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count《endcount);
irdata=irdata》》1;
}
//Send the complement of eight-bit data
irdata=~p_irdata;
for(i=0;i《8;i++)
{
endcount=10;
flag=1;
count=0;
do{}while(count《endcount);
if(irdata-(irdata/2)*2)
{
endcount=41;
}
else
{
endcount=15;
}
flag=0;
count=0;
do{}while(count《endcount);
irdata=irdata》》1;
}
endcount=10;
flag=1;
count=0;
do{}while(count《endcount);
flag=0;
}
void delay()
{
int i,j;
for(i=0;i《400;i++)
{
for(j=0;j《100;j++)
{
}
}
}
Previous article:C51 programming experience summary sharing
Next article:Design of audio signal amplitude equalization control amplification circuit based on AT89C51 microcontroller and amplifier
- 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
- CGD and Qorvo to jointly revolutionize motor control solutions
- CGD and Qorvo to jointly revolutionize motor control solutions
- Keysight Technologies FieldFox handheld analyzer with VDI spread spectrum module to achieve millimeter wave analysis function
- Infineon's PASCO2V15 XENSIV PAS CO2 5V Sensor Now Available at Mouser for Accurate CO2 Level Measurement
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- Advanced gameplay, Harting takes your PCB board connection to a new level!
- A new chapter in Great Wall Motors R&D: solid-state battery technology leads the future
- Naxin Micro provides full-scenario GaN driver IC solutions
- Interpreting Huawei’s new solid-state battery patent, will it challenge CATL in 2030?
- Are pure electric/plug-in hybrid vehicles going crazy? A Chinese company has launched the world's first -40℃ dischargeable hybrid battery that is not afraid of cold
- Common Problems of C2000 in Real-time Control Systems
- LLC parameter design, cannot achieve ZVS
- Soldering methods and precautions for chip crystal oscillators
- Guangzhou Power Chip Sales and FAE Recruitment
- I don't understand why the feedback network of the op amp is connected to the non-inverting terminal. What is the purpose of this?
- Matlab Neural Network Principles and Examples
- TI XDC Tool Overview
- Robotic arm end motion stability evaluation (with Linux real-time waveform client source code)
- SPI bus easy to understand explanation
- Senior engineers explain the simulation and optimization analysis of automotive electronic CAN bus