Infrared remote control decoding program written in C language

Publisher:平安幸福Latest update time:2012-11-06 Source: 21ic Reading articles on mobile phones Scan QR code
Read articles on your mobile phone anytime, anywhere

#include "STC89C51RC.H"

sbit DQ = P4^3;
sbit SPK = P1^0;


#include

#define seg1 XBYTE[0xffec]
#define seg2 XBYTE[0xffed]
#define seg3 XBYTE[0xffee]
#define seg4 XBYTE[0xffef]
unsigned char IRMcode[4];

unsigned char code ledmap[]= //Common cathode LED digital tube decoding table
{
0x3f,0x06,0x5b,0x4f,0x66, //0,1,2,3,4,
0x6d,0x7d,0x07,0x7f,0x6f, //5,6,7,8,9,
0x77,0x7C,0x39,0x5E,0x79, //A,b,C,d,E,
0x71, //F,
};

void delay(unsigned int);

void main()
{
EA = 1;
EX2 = 1;
while(1)
{

if (IRMcode[2]==~IRMcode[3]){
seg1 = ~ledmap[IRMcode[2]/100];
seg2 = ~ledmap[IRMcode[2]/10%10];
seg3 = ~ledmap[IRMcode[2]%10];
seg4 = 0xff;//熄灭
}
}
}

void Sound(void)
{
SPK = 0;
delay(10000);
SPK = 1;
}

void IRMint(void) interrupt 6 using 2
{
unsigned char count;
unsigned int count1;
unsigned char i,j;
EA = 0;
count = 9;
while(--count)
{
delay(100);//440us
if(DQ){EA = 1;return;}
}
while(DQ==0);//Through the remaining low level of the boot code
//The above completes the 4.5ms low level detection of the boot code

count = 9;
count1 = 0;
while(--count)
{
delay(100);//440us
if(DQ==0){EA = 1;return;}
}
while(DQ==1)//Through the remaining high level of the boot code
{
if(count1++>1000) {
P1=0x55;EA = 1;return;}
}
//The above completes the 4.5ms high level detection of the boot code

count1 = 0;
for(j=0;j<4;j++)//setting the number of valid bytes
{
for(i=0;i<8;i++)//number of byte bits
{
while(DQ==0);//pass the low level of encoding
delay(200);//delay to determine the length of maintaining the high level of encoding
IRMcode[j]<<=1;
if(DQ)IRMcode[j]|=0x01;
while(DQ==1){//pass the remaining high level of encodingif
(count1++>2000){EA = 1;return;}
}
}
}

Sound();
EA = 1;
}

//General delay function
//22.1184,10 = 48.4 us (5us+43.4)
//22.1184,100 = 439 us (43.4*10+5)
//22.1184,1000 = 4345 us(43.4*100+5)
//22.1184,10000 = 43450 us(43.45*1000+5)
void delay(unsigned int t)
{
while(--t);
}

Reference address:Infrared remote control decoding program written in C language

Previous article:Application of single chip microcomputer in stress magnetic measurement device
Next article:Design of infrared remote control decoder

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号