当前位置:网站首页>(15) Infrared communication
(15) Infrared communication
2022-06-11 05:17:00 【I love notes】
In this section, we mainly explain the content of infrared communication , We passed one of our infrared emitters ( Like a remote control ) To the... Connected to the infrared receiver 51 Single chip computer sends an infrared signal , After receiving the signal, the infrared receiver will display the specific key value on our digital tube .
About infrared light :
The order of light that human beings can see from long to short is rainbow seven colors : red , orange , yellow , green , green , blue , purple . The wavelength range of red light is 0.62~0.76um; The wavelength range of violet light is 0.38~046um; Light with shorter wavelength than violet light is called ultraviolet , Light longer than red light is called infrared . Infrared remote control uses the wavelength of 0.76um~1.5um Between the infrared ray to control the signal . And because infrared light does not have the ability to penetrate the wall , Although it is a drawback , But it can also be called its advantages , This also provides conditions for large-scale use , Every household can use the same frequency infrared remote control without channel changing .
Infrared remote control communication is generally composed of two infrared transmitting devices and infrared receiving devices
About infrared emitting devices , That is what we call the remote control , The common carrier frequency is 38kHz, This is due to the 455kHz Frequency dependent , At the transmitter, divide the integer frequency , It's usually 12 frequency division , So the frequency of the transmitter is 455/12=37.9, About equal to 38, Of course, some infrared frequencies are 36kHz,40kHz etc. , Generally, this frequency is determined by the frequency of the transmitter . There are two forms of binary pulse code between two devices , It means that there are two forms to represent high pulse and low pulse , What I am using now is NEC Protocol Of PWM code , This code is characterized by 8 Bit address and 8 Bit instruction length , Address and command are transmitted twice ,PWM Pulse position modulation , It is represented by the duty cycle of the transmitted infrared carrier 0 and 1, What does that mean ? Every logic 0 perhaps 1 It's all about 560us Is a basic unit , If we want to express a logic 1, Then we need to send a 560us Pulse and three 560us Low level of , If we want to express a logic 0, Just one 560us And a 560us Low level of . The receiving of the infrared receiving head is just opposite to the logic of the transmission , This means that the infrared transmitter emits a high level , Then our infrared receiver will receive a low level , And you send a low level and you receive a low level , As for the principle, we don't need to understand , It's actually an agreement . We just talked about the representation of high and low levels , So how do we send a data ? The process of infrared transmission is actually the transmission of several codes , Its data format is : Pilot code , Address code , Address inversion , Control code , Control the irony . The pilot code consists of a 9ms Low level and a 4.5ms High level composition of , The rest are made up of 8 A composition . The meaning of inverse code is to verify whether you receive correctly . Increase the reliability of transmission .NEC Code also specifies the serial code , It is used to count if you haven't released it after you press it , You can count the length or number of keystrokes by counting the number of consecutive codes . You can check the specific serial number .
Hardware :
This is mine 51 MCU infrared receiving module content , My single chip computer has passed P32 Communicate with the infrared module , See if there is an infrared transmitter to send content to the infrared module

Software :
our P32 It happens to be an interrupt pin , We can determine whether the infrared signal is sent by determining whether there is a pilot code , There is a bad thing about this code , It can't be said that , This is also the limitation of SCM . That is to write all the judgment contents into the interrupt , This can easily affect the normal operation of other programs in large programs , Because the interruption time is too long , But if not written in interrupt , It may also be affected by other interruptions . But there will be no problem with this program , After all, only such a program is running . So there is no problem writing it in the interrupt . We use the digital tube to display the address code we received . The code is as follows :
#include "reg52.h"
#include "main.h"
#include "ir.h"
sbit IRIN = P3^2;
int Time;
unsigned char IrValue[4] = {0,0,0,0};
void delay(int xms){
while(xms--);
}
void ir_init(){
IT0 = 1;
EX0 = 1;
EA = 1;
IRIN = 1;
}
void ir_check(){
unsigned char j,k;
unsigned short err;
Time=0;
delay(700);
if(IRIN==0)
{
err=1000;
while((IRIN==0)&&(err>0))
{
delay(1);
err--;
}
if(IRIN==1)
{
err=500;
while((IRIN==1)&&(err>0))
{
delay(1);
err--;
}
for(k=0;k<4;k++)
{
for(j=0;j<8;j++)
{
err=60;
while((IRIN==0)&&(err>0))
{
delay(1);
err--;
}
err=500;
while((IRIN==1)&&(err>0))
{
delay(10); //0.1ms
Time++;
err--;
if(Time>30)
{
return;
}
}
IrValue[k]>>=1;
if(Time>=8)
{
IrValue[k]|=0x80;
}
Time=0;
}
}
}
if(IrValue[2]!=~IrValue[3])
{
return;
}
}
}
void main(){
ir_init();
while(1){
display(IrValue[2]);
}
}
void ir_interrupt() interrupt 1{
IT0 = 0;
ir_check();
IRIN = 1;
IT0 = 1;
}The code of the nixie tube is as follows
#include "reg52.h"
#include "main.h"
sbit LSA = P2^2;
sbit LSB = P2^3;
sbit LSC = P2^4;
unsigned char code smgduan[17]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,
0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};// Show 0~F Value
void display(int val){
char temp[3];
int i;
temp[0] = 0x76;
temp[1] = smgduan[val % 16];
temp[2] = smgduan[val / 16];
for(i = 0;i < 3;i++){
switch(i){
case 0:
LSA = 0; LSB = 0; LSC = 0;
break;
case 1:
LSA = 1; LSB = 0; LSC = 0;
break;
case 2:
LSA = 0; LSB = 1; LSC = 0;
break;
}
P0 = temp[i];
delay(100);
P0 = 0x00;
}
}The two header files are as follows :
#ifndef _MAIN_H_
#define _MAIN_H_
void delay(int xms);
#endif#ifndef _IR_H_
#define _IR_H_
void display(int val);
#endif边栏推荐
- Analysis while experiment - a little optimization of memory leakage in kotlin
- lower_ Personal understanding of bound function
- Tianchi - student test score forecast
- Parametric contractual learning: comparative learning in long tail problems
- Section IV: composition and materials of asphalt mixture (2) -- main materials of asphalt
- Paper recommendation: relicv2, can the new self supervised learning surpass supervised learning on RESNET?
- [aaai 2021 timing action nomination generation] detailed interpretation of bsn++ long article
- Comparison of gigabit network card chips: who is better, a rising star or a Jianghu elder?
- QT Road (2) -- HelloWorld
- The solution "no hardware is configured for this address and cannot be modified" appears during botu simulation
猜你喜欢

jvm调优六:GC日志分析和常量池详解

Iris dataset - Introduction to machine learning

New library goes online | cnopendata immovable cultural relic data

Emnlp2021 𞓜 a small number of data relation extraction papers of deepblueai team were hired

Wechat applet uploads the data obtained from database 1 to database 2

6 questions to ask when selecting a digital asset custodian

WinForm (II) advanced WinForm and use of complex controls

Sealem finance builds Web3 decentralized financial platform infrastructure

Analysis while experiment - a little optimization of memory leakage in kotlin

微信小程序,购买商品属性自动换行,固定div个数,超出部分自动换行
随机推荐
PCB走线到底能承载多大电流
Sealem finance builds Web3 decentralized financial platform infrastructure
What is the difference between gigabit network card and 10 Gigabit network card?
Section II: structural composition characteristics of asphalt pavement (1) structural composition
Sealem Finance打造Web3去中心化金融平台基础设施
华为设备配置通过GRE接入虚拟专用网
Iris dataset - Introduction to machine learning
ROS compilation error: could not find a package configuration file provided by "XXX“
WinForm (I) introduction to WinForm and use of basic controls
Feynman learning method
Zed2 running vins-mono preliminary test
Course design summary
NVIDIA SMI has failed because it could't communicate with the NVIDIA driver
35.搜索插入位置
About custom comparison methods of classes and custom methods of sort functions
mysql字符串转数组,合并结果集,转成数组
lower_ Personal understanding of bound function
How to purchase 25g optical network card
Network adapter purchase guide
Reverse thinking: making cartoon photos real