51 MCU infrared remote control decoding

Publisher:大橙子5511Latest update time:2011-10-24 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The infrared remote control transmitter chip adopts PPM encoding. When the transmitter button is pressed, a set of 108ms encoding pulses will be emitted. The remote control encoding pulse consists of a preamble, an 8-bit user code, an 8-bit inverse code of the user code, an 8-bit operation code, and an 8-bit inverse code of the operation code. By checking the user code, each remote control can only control the action of one device, which can effectively prevent interference between multiple devices. The encoding must be followed by an inverse code to verify the correctness of the encoding reception, prevent misoperation, and enhance the reliability of the system. The preamble is the starting part of a remote control code, consisting of a 9ms low level (start code) and a 4.5ms high level (result code), which serves as a preparation pulse for receiving data. The combination of a pulse width of 0.56ms and a period of 1.12ms represents a binary "0"; the combination of a pulse width of 1.68ms and a period of 2.24ms represents a binary "1". If the key is pressed for more than 108ms and is not released, the next transmitted code (burst code) will only consist of the start code (9ms) and the end code (2.5ms).

The MCU uses the external interrupt INTI pin to connect to the signal line of the infrared receiver, and the interrupt mode is edge triggered. Timer 0 is used to calculate the interval of the interrupt to distinguish the leading code, binary "1", and "0" codes. The 8-bit operation code is extracted and displayed on the digital tube.

// The decoded value is in Im[2]. When IrOK=1, the decoding is valid.
/* 51 MCU infrared remote control decoding program*/
// Aim the remote control at the infrared receiver, press the remote control button, and the code of the corresponding button will be displayed on the first two digits of the digital tube

#include
#define uchar unsigned char
sbit dula=P2^6;
sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,
0x07,0x7f ,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};

uchar f;

#define Imax 14000 //This is the value when the crystal is 11.0592,
#define Imin 8000 //If you use a crystal with other frequencies,
#define Inum1 1450 //You need to change the corresponding value.
#define Inum2 700
#define Inum3 3000

unsigned char Im[4]={0x00,0x00,0x00,0x00};
uchar show[2]={0,0};
unsigned long m,Tc;
unsigned char IrOK;


void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}

void display()
{
dula=0;
P0=table[show[0]];
dula=1;
dula=0;

wela=0;
P0=0xfe;
wela=1;
wela=0;
delay(5);

P0= table[show[1]];
dula=1;
dula=0;

P0=0xfd;
wela=1;
wela=0;
delay(5);
}

//External interrupt decoding program
void intersvr1(void) interrupt 2 using 1
{
Tc=TH0*256+TL0; //Extract interrupt time interval
TH0=0;
TL0=0; //Reset the timer interrupt
if((Tc>Imin)&&(Tc {
m=0;
f=1;
return;
} //Find the start code
if(f==1)
{
if(Tc>Inum1&&Tc {
Im[m/8]=Im[m/8]>>1|0x80; m++;
}
if(Tc>Inum2&&Tc {
Im[m/8]=Im[m/8]>>1; m++; //Get code
}
if(m==32)
{
m=0;
f=0;
if(Im[2]==~Im[3])
{
IrOK=1;
}
else IrOK=0; //After the code is retrieved, determine whether the code is read correctly
}
//Prepare to read the next code
}

}


/*Demonstration main program*/
void main(void)
{
unsigned int a;

m=0;
f=0;
EA=1;

IT1=1;EX1=1;

TMOD=0x11;
TH0=0;TL0=0;
TR0=1;//ET0=1;

while(1)
{

if(IrOK==1)
{
show[1]=Im[2] & 0x0F; //Get the lower four bits of the key code
show[0]=Im[2] >> 4;
IrOK=0;

}
for(a=100;a>0;a--)
{
display();
}

}
}

Reference address:51 MCU infrared remote control decoding

Previous article:Improved float type liquid level meter based on MSP430F133 single chip microcomputer
Next article:Application example of AT88SC1604 card controlled by single chip microcomputer

Latest Industrial Control Articles
Change More Related Popular Components

EEWorld
subscription
account

EEWorld
service
account

Automotive
development
circle

About Us Customer Service Contact Information Datasheet Sitemap LatestNews


Room 1530, 15th Floor, Building B, No.18 Zhongguancun Street, Haidian District, Beijing, Postal Code: 100190 China Telephone: 008610 8235 0740

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京ICP证060456号 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号