First understand the principle of infrared reception:
The remote control is easy to use and has many functions. It has been widely used in various household appliances such as TVs, VCDs, DVDs, air conditioners, etc. It is cheap and easy to buy on the market. If many buttons on the remote control can be decoded and used as inputs of the single-chip system, it will solve the problems of conventional matrix keyboard circuit boards being too large, wiring complex, and occupying too many I/O ports. Moreover, by using the remote control, the separation of people and equipment can be achieved during operation, making it more convenient to use.
1. Coding format
1. Coding of 0 and 1
The signal transmitted by the remote control consists of a string of binary codes of 0 and 1. Different chips have different encodings for 0 and 1. Usually there are Manchester encoding and pulse width encoding. The 0 and 1 of TC9012 are encoded using the PWM method, that is, pulse width modulation. Its 0 code and 1 code are shown in Figure 1 (taking the waveform of the remote control receiving output as an example). The 0 code is composed of a 0.56ms low level and a 0.56ms high level. The pulse width is 1.12ms. The 1 code is composed of a 0.56ms low level and a 1.69ms high level. The pulse width is 2.25ms. When writing a decoding program, you can get 0 or 1 by judging the width of the pulse.
2. Key coding
When a key is pressed for more than 36ms, the oscillator activates the chip and transmits a set of 108ms coded pulses. The 108ms transmission code consists of a start code (9ms), a result code (4.5ms), a low 8-bit address code (9ms~18ms), a high 8-bit address code (9ms~18ms), an 8-bit data code (9ms~18ms) and the inverse code of the 8-bit data (9ms~18ms). If the key is pressed for more than 108ms and is not released, the next transmitted code (continuous code) will only consist of the start code (9ms) and the end code (2.5ms).
When we press the button of the remote control, the remote control will send out a string of binary codes as shown in Figure 2, which we call a frame of data. According to the function of each part, they can be divided into 5 parts, namely, the guide code, address code, address code, data code, and data inverse code. When the remote control transmits the code, the low bit is in front and the high bit is in the back. From the analysis of Figure 2, we can get that The high level of the boot code is 4.5ms, and the low level is 4.5ms. When this
code is received, it indicates the beginning of a frame of data. The single chip can prepare to receive the following data. The address code consists of 8 bits of binary, with a total of 256 types. The address code is repeated once in the figure. It is mainly to enhance the reliability of the remote control. If the two address codes are different, it means that the data of this frame is wrong and should be discarded. Different devices can have different address codes. Therefore, remote controls with the same encoding will not interfere with each other as long as the address codes are set differently. The address code in the figure is hexadecimal 0EH (note that the low bit is in front). In the same remote control, the address code sent by all buttons is the same. The data code is 8 bits and can encode 256 states, representing the actual keys pressed. The data inverse code is the inverse of each bit of the data code. By comparing the data code with the data inverse code, it can be determined whether the received data is correct. If the relationship between the data code and the data inverse code does not meet the opposite relationship, the remote control reception is wrong and the data should be discarded. On the same remote control, the data codes of all buttons are different. In Figure 2, the data code is hexadecimal 0CH, and the data inverse code is hexadecimal 0F3H (note that the low bit is in the front). The sum of the two should be 0FFH.
Continuous code
2. Single-chip remote control receiving circuit
Infrared remote control receiving can adopt the earlier infrared receiving diode plus a dedicated infrared processing circuit method. Such as CXA20106, this method has a complex circuit and is generally not used now. A better receiving method is to use an integrated infrared receiving head, which combines infrared receiving diodes, amplification, demodulation, shaping and other circuits together, with only three pins. They are +5V power supply, ground, and signal output. The appearance and pins of the commonly used integrated receiving head are shown in Figures 3 and 4. The signal output of the infrared receiving head is
connected to the INTO or INT1 pin of the single-chip microcomputer. The typical circuit is shown in Figure 5. A PNP transistor is added in the figure to amplify the output signal.
For the remote control end (decoding end, the receiving end can just invert this)
Guide code: 9ms high + 4.5ms low
System code: System code 1 + System code 2 (consisting of "0" and "1" that define high and low levels)
Data code: Data code 1 + Data inverse code (consisting of "0" and "1" that define high and low levels)
Remaining code: 108ms - Guide code occupied time - System code occupied time - Data code occupied time.
If the "key" is pressed for more than 108ms, the remote control will also send a retransmission code:
The format of the retransmission code (108ms) is as follows:
9ms high + 2.25ms low + 0.56ms high + 96.19ms low
Connection circuit diagram:
Let's start writing the program:
#ifndef MAIN_H
#define MAIN_H
#include
#define bitset(var,bitno)(var |=1< //Define the receiving frame status #endif typedef struct frame1 void int_delay(uint count) void interrupt main_int() if(INTF&INTEDG) switch(frame.ir_state) } } frame.temp=frame.temp<<1; init_all() ; if(frame.ready==1) }
#define uint unsigned int
#define uchar unsigned char
#define IR_IDLE 0x01
#define IR_START 0x02
#define IR_ADD 0x03
#define IR_ADDINV 0x04
#define IR_DATA 0x05
#define IR_DATAINV 0x06
#define ms_168 0x0600
#define ms_th 0x08CA
#define ms_9 0x0800
#define ms_306 0x0B00
#define ms_125 0x1300
#define ms_15 0x15F9
//void DelayMS(uint ms);//millisecond delay function
//void Delay10US(uint us);//10 microsecond delay function
void init_all();
#include "main.h"
#include "t232.h"
{
uint add;
uint addinv;
uchar data;
uchar datainv;
uchar ir_state;
uint count;
uint temp;
uchar ready;
} ir_frame;
{
while(count--);
}
//define global variable
ir_frame frame;
{
{
GIE=0;
INTF=0;
TMR1ON=0;
frame.count=TMR1H*256+TMR1L;
TMR1H=0;
TMR1L=0;
TMR1ON=1;
{
case IR_IDLE :
if(frame.count>0x2000)//Prevent interference
frame.ir_state=IR_START ;
break ;
case IR_START :
if(frame.ready==1)//No processing, waiting
{
frame .ir_state=IR_IDLE ;
return ;
}
if((frame.count>ms_125)&&(frame.count
frame.add=0 ;
frame.addinv=0 ;
frame.data=0 ;
frame .datainv=0 ;
frame.ir_state=IR_ADD ;
frame.temp=1 ;
frame.ready=0 ;
else if((frame.count>ms_9)&&(frame.count
frame.ready=1;
frame.ir_state = IR_IDLE;
else//Noise?
{
frame.ir_state = IR_IDLE;
}
break;
case IR_ADD:
if(frame.count<0x280)//Noise?
return;
if((frame.count>ms_168))//High level?
frame.add|=frame.temp;
frame.temp=frame.temp<<1;
if(frame.temp==0x2000)//13 bits OK?
{
frame.ir_state=IR_ADDINV ;
frame.temp=1 ;
}
break ;
case IR_ADDINV :
// int_delay(75) ;
// if(RB0)
if(frame.count<0x280)
return ;
if((frame.count>ms_168 ))
frame.addinv|=frame.temp;
frame.temp=frame.temp<<1;
if(frame.temp==0x2000)//13 bits OK?
{
frame.ir_state=IR_DATA;
frame.temp=1;
}
break ;
case IR_DATA :
if(frame.count<0x280)//Noise
return ;
if((frame.count>ms_168))//High level
frame.data|=frame.temp;
if(frame.temp==0x0100)//8-bit finished?
{
frame.ir_state=IR_DATAINV;
frame.temp=1;
}
break;
case IR_DATAINV:
if(frame.count <0x280)
return ;
if((frame.count>ms_168))
frame.datainv|=frame.temp ;
frame.temp=frame.temp<<1 ;
if(frame.temp==0x0080)//7 bits finished?
{
frame.temp=frame.temp<<1;
int_delay(75);//Delay waiting for the level of the last bit
if(RB0)
frame.datainv|=frame.temp;
if((frame.data|frame. datainv==0xff)&&(frame.add==0x011F))
{
frame.ready=1;
}
frame.ir_state=IR_IDLE ;
}
break ;
default :
break ;
}
GIE=1 ;
}
}
void init_all()
{
init_232() ;
//init_hongwai() ;
INTCON=0 ;
INTE=1;//Turn on RB level interrupt
PEIE=1;
INTEDG=1 ;
TRISB0=1;//RB4 is input
T1CON=0 ;
TMR1H=0xAA ;
TMR1L=0xBB ;
frame.ir_state=IR_IDLE ;
GIE=1 ;
ADCON0=0x06 ;
TRISA0=0 ;
}
void main()
{
const char str[]= "hello world !" ;
send_str(str) ; //Test serial port
while(1)
{
{
put_char(frame.data) ;
frame.ready=0 ;
}
}
Previous article:PIC drives JM240128 LCD
Next article:PIC16F877A drives DS18B20 temperature acquisition chip
- 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
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Microchip Accelerates Real-Time Edge AI Deployment with NVIDIA Holoscan Platform
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Melexis launches ultra-low power automotive contactless micro-power switch chip
- Molex leverages SAP solutions to drive smart supply chain collaboration
- Pickering Launches New Future-Proof PXIe Single-Slot Controller for High-Performance Test and Measurement Applications
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- Apple faces class action lawsuit from 40 million UK iCloud users, faces $27.6 billion in claims
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- The US asked TSMC to restrict the export of high-end chips, and the Ministry of Commerce responded
- PWM signal reading problem (please delete the post if the method has changed)
- Why is the timer called TIMER RA in Renesas R8 microcontroller? Isn't it usually TIMER1 or TIMER2?
- I have discovered a wave of MCU software and hardware anti-interference operations. Which ones are commonly used by front-line engineers in the forum?
- Pioneer official engineer's practical knowledge: HPM6000 series Security Flash introduction
- [Evaluation and experience of Zhongke Yihaiwei EQ6HL45 development platform] +04.RTC board test and debug (zmj)
- Xianji official engineer's dry goods: How to use the HPM6000 series on-chip SRAM
- Gizwits IoT Platform + MSP430G2553 + Low-power Li-ion Battery Smart Manager
- Is it better to use logic level MOS or standard level MOS for DCDC circuit driving?
- A small question about COMSOL
- It's settled. Twitter is laying off more than 50% of its employees. The ratio of M to IC is 1:20. All top executives will be laid off.