Use AT89S51 microcontroller to make an infrared remote control.

Publisher:采菊东篱下Latest update time:2023-06-28 Source: elecfansKeywords:AT89S51 Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

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++)

{

}

}

}


Keywords:AT89S51 Reference address:Use AT89S51 microcontroller to make an infrared remote control.

Previous article:C51 programming experience summary sharing
Next article:Design of audio signal amplitude equalization control amplification circuit based on AT89C51 microcontroller and amplifier

Latest Microcontroller 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号