Infrared remote control design of smart home based on ESP8266 microcontroller

Publisher:脑洞飞翔Latest update time:2021-12-15 Source: eefocusKeywords:MCU Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

The PCB schematic is as follows. I remember it was drawn with protel at that time.

insert image description here

The circuit schematic is as follows: Drawing software is the same as above

insert image description here

Experiment reference C language code

#include "stc12c2052ad.h"

#include "wifi_IR.h"


#include


//#define ENABLE_IAP 0x83 //if SYSCLK<20MHz


#define FOSC 11059200UL //12M crystal


#define CMD_IDLE 0 //Stand-By

#define CMD_READ 1 //Byte-Read

#define CMD_PROGRAM 2 //Byte-Program

#define CMD_ERASE 3 //Sector-Erase


uint addr; //EPPROM address

//uchar cou;

bit study_send_switch,LED_state;


void SaveLevelTimeLength(uint addr); //Store level time

void IrSend(); //infrared transmission

void Read_Key();

void IrStudy();

void IapIdle();

void byte_write(uint addr, uchar dat);

void SectorErase(uint sector_addr);

uchar byte_read(uint addr);


void TIMER0_RELOAD(uint addr) //load timer

{

TR0=0;

TF0=0;

TH0=byte_read(addr); //Read the length of the level from the specified address

TL0=byte_read(addr+1); //Read the length of the level from the specified address

TR0=1; //Start the timer


}

//---------------------------------------------------


void IrSend() // infrared transmission

{

uchar level_cnt; //Number of levels


level_cnt=byte_read(addr); //Read the number of levels

addr++; //move the address back one position

while (1)

{

F38_4KHZ_ON(); //Because most of the infrared codes start with a high level, this is turned on from the beginning.

TIMER0_RELOAD(addr); //Load the duration into the timer and start timing

addr+=2; // The address is moved to a place that has not been taken before. The TIMER0_RELOAD function takes the data of two addresses

while (!TF0); //Wait for timer 0 to overflow


if(level_cnt–==0)break;//Judge whether the acquisition is completed

F38_4KHZ_OFF(); IR_SEND = 1; //stop transmitting

TIMER0_RELOAD(addr); //Load the duration into the timer and start timing

addr+=2; //The address is moved to a place that has not been taken before. The TIMER0_RELOAD function takes the data of two addresses

while (!TF0); //Wait for timer 0 to overflow

if(level_cnt–==0)break;//Is the level completed?

}

F38_4KHZ_OFF(); IR_SEND = 1; //stop transmitting

}

//---------------------------------------------------


void SaveLevelTimeLength(uint addr) //Save level time

{

TR0=0;

byte_write(addr, ~TH0);

byte_write(addr+1, ~TL0); //Store the level duration in eeprom

TH0=0; //The timer initial value is reset to 0

TL0=0x65; //According to the manual, it takes 55us to program one byte, and 110us to program two bytes.

TR0=1; //Start counting

}


void IrStudy()

{

uint level_cnt;

uint addrtmp;


TF0 = 0;

SectorErase(addr);

addrtmp=addr; //Record the first address and store the number of levels

addr++;

TR0=0; //stop counting

while (IR_REV); //Wait for the infrared receiving pin to be low

//Encoding and decoding are a pair of inverse processes. Not only in principle, they are also inverse processes in the code sending and receiving process. That is, the original signal at the transmitting end is a high level, and the output of the receiving head is a low level.

TH0=0;

TL0=0;

TR0=1; //Start the timer


while (1)

{

while (!IR_REV) //Wait for high level, wait for timeout; exit after 70MS

{

if (TF0)

{

goto StudyFinish;

}


}


SaveLevelTimeLength(addr); //When high level arrives, save low level duration to eeprom}

level_cnt++;

addr += 2;


while (IR_REV) //Wait for low level, wait for timeout; exit after 70MS

{

if (TF0)

{

goto StudyFinish;

}

}

SaveLevelTimeLength(addr); // Save the high level time when the low level arrives

level_cnt++; //The number of stored levels plus 11

addr+=2; //Address moves two digits backward

}

StudyFinish:

TF0=0;

TR0=0;

byte_write(addrtmp,level_cnt);

level_cnt = 0;


}


void Delay100ms() //@11.0592MHz

{

unsigned char i, j, k;


nop();

nop();

i = 5;

j = 52;

k = 195;

do

{

do

{

while (–k);

} while (–j);

} while (–i);

}


void IapIdle()

{

IAP_CONTR = 0; //Close IAP function

IAP_CMD = 0; //Clear command to standby

IAP_TRIG = 0; //Clear trigger register

IAP_ADDRH = 0x80; //Data ptr point to non-EEPROM area

IAP_ADDRL = 0; //Clear IAP address to prevent misuse

}


/************************************************************************

Function name: Byte Write

Global variables: None

Parameter description: addr: write address, dat: write data

****************************************************************************/

void byte_write(uint addr,uchar dat)

{

IAP_CONTR = ENABLE_IAP; //Open IAP function, and set wait time

IAP_CMD = CMD_PROGRAM; //Set ISP/IAP/EEPROM PROGRAM command

IAP_ADDRL = addr; //Set ISP/IAP/EEPROM address low

IAP_ADDRH = addr >> 8; //Set ISP/IAP/EEPROM address high

IAP_DATA = dat; //Write ISP/IAP/EEPROM data

IAP_TRIG = 0x46; //Send trigger command1 (0x46)

IAP_TRIG = 0xb9; //Send trigger command2 (0xb9)

nop();

nop();

nop();

nop();

IapIdle();


}

Keywords:MCU Reference address:Infrared remote control design of smart home based on ESP8266 microcontroller

Previous article:Application of MCU 74LS138
Next article:Graduation Project of Temperature Controller Using PID Algorithm for 51 Single Chip Microcomputer

Latest Microcontroller Articles
  • Download from the Internet--ARM Getting Started Notes
    A brief introduction: From today on, the ARM notebook of the rookie is open, and it can be regarded as a place to store these notes. Why publish it? Maybe you are interested in it. In fact, the reason for these notes is ...
  • Learn ARM development(22)
    Turning off and on interrupts Interrupts are an efficient dialogue mechanism, but sometimes you don't want to interrupt the program while it is running. For example, when you are printing something, the program suddenly interrupts and another ...
  • Learn ARM development(21)
    First, declare the task pointer, because it will be used later. Task pointer volatile TASK_TCB* volatile g_pCurrentTask = NULL;volatile TASK_TCB* vol ...
  • Learn ARM development(20)
    With the previous Tick interrupt, the basic task switching conditions are ready. However, this "easterly" is also difficult to understand. Only through continuous practice can we understand it. ...
  • Learn ARM development(19)
    After many days of hard work, I finally got the interrupt working. But in order to allow RTOS to use timer interrupts, what kind of interrupts can be implemented in S3C44B0? There are two methods in S3C44B0. ...
  • Learn ARM development(14)
  • Learn ARM development(15)
  • Learn ARM development(16)
  • Learn ARM development(17)
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号