红外遥控接收
时间:10-02
整理:3721RD
点击:
#include "hongwai.h"
# include "FSM_Task.h"
#include "LCD1602.h"
#include <macroconst.h>
uchar dat1[4]={0,0,0,0};
unsigned char hongwainum=33;
bit hongwaiflag=0;
void hongwai_initial()
{
TMOD=0x01;
EA=1;
EX0=1;
}
void delay0(uchar x) ;
void beep();
void delay0(uchar x) //x*0.14MS
{
unsigned char i;
while(x--)
{
for (i = 0; i<13; i++) {}
}
}
void beep() //蜂鸣器响一声函数
{
unsigned char i;
for (i=0;i<100;i++)
{
delay0(4);
buzzer=!buzzer; //BEEP取反
}
buzzer=1; //关闭蜂鸣器
//Delay1ms(200); //延时
}
void int0(void) interrupt 0
{
uchar i,j;
EX0=0;
i=10;
while(--i)
{
TH0=0xfc;
TL0=0xe7;
TR0=1;
while(!TF0); //延时860毫秒
TF0=0;
TR0=0;
if(irpot) {EX0=1; return ;}
}
while(!irpot);
TH0=0xf6;
TL0=0xff;
TR0=1;
while(!TF0);
TF0=0;
TR0=0; //延时2500毫秒
if(!irpot)
{
EX0=1;
return;
}
while(irpot);
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
while(!irpot);
dat1[i]>>=1;
TH0=0xfc;
TL0=0xe7;
TR0=1;
while(!TF0);
TR0=0;
TF0=0; //延时860us
if(irpot)
{
dat1[i]|=0x80; //dat1[2]为所需数据
while(irpot);
}
}
}
switch(dat1[2])
{
case 0x43: hongwainum=10;break; //模式键
case 0x09: hongwainum=11;break; //退出键
case 0x15: hongwainum=12;break; //升键
case 0x07: hongwainum=13;break; //降键
case 0x44: hongwainum=14;break; //左移
case 0x40: hongwainum=15;break; //右移
case 0x16: hongwainum=0;break; // 0
case 0x0c: hongwainum=1;break; // 1
case 0x18: hongwainum=2;break; // 2
case 0x5e: hongwainum=3;break; // 3
case 0x08: hongwainum=4;break; // 4
case 0x1c: hongwainum=5;break; // 5
case 0x5a: hongwainum=6;break; // 6
case 0x42: hongwainum=7;break; // 7
case 0x52: hongwainum=8;break; // 8
case 0x4a: hongwainum=9;break; // 9
default: hongwainum=33;break;
}
if(hongwainum!=33)
{
beep();
hongwaiflag=1;
}
EX0=1;
return;
}
求大神帮我看看这段程序是如何实现解码接收的
# include "FSM_Task.h"
#include "LCD1602.h"
#include <macroconst.h>
uchar dat1[4]={0,0,0,0};
unsigned char hongwainum=33;
bit hongwaiflag=0;
void hongwai_initial()
{
TMOD=0x01;
EA=1;
EX0=1;
}
void delay0(uchar x) ;
void beep();
void delay0(uchar x) //x*0.14MS
{
unsigned char i;
while(x--)
{
for (i = 0; i<13; i++) {}
}
}
void beep() //蜂鸣器响一声函数
{
unsigned char i;
for (i=0;i<100;i++)
{
delay0(4);
buzzer=!buzzer; //BEEP取反
}
buzzer=1; //关闭蜂鸣器
//Delay1ms(200); //延时
}
void int0(void) interrupt 0
{
uchar i,j;
EX0=0;
i=10;
while(--i)
{
TH0=0xfc;
TL0=0xe7;
TR0=1;
while(!TF0); //延时860毫秒
TF0=0;
TR0=0;
if(irpot) {EX0=1; return ;}
}
while(!irpot);
TH0=0xf6;
TL0=0xff;
TR0=1;
while(!TF0);
TF0=0;
TR0=0; //延时2500毫秒
if(!irpot)
{
EX0=1;
return;
}
while(irpot);
for(i=0;i<4;i++)
{
for(j=0;j<8;j++)
{
while(!irpot);
dat1[i]>>=1;
TH0=0xfc;
TL0=0xe7;
TR0=1;
while(!TF0);
TR0=0;
TF0=0; //延时860us
if(irpot)
{
dat1[i]|=0x80; //dat1[2]为所需数据
while(irpot);
}
}
}
switch(dat1[2])
{
case 0x43: hongwainum=10;break; //模式键
case 0x09: hongwainum=11;break; //退出键
case 0x15: hongwainum=12;break; //升键
case 0x07: hongwainum=13;break; //降键
case 0x44: hongwainum=14;break; //左移
case 0x40: hongwainum=15;break; //右移
case 0x16: hongwainum=0;break; // 0
case 0x0c: hongwainum=1;break; // 1
case 0x18: hongwainum=2;break; // 2
case 0x5e: hongwainum=3;break; // 3
case 0x08: hongwainum=4;break; // 4
case 0x1c: hongwainum=5;break; // 5
case 0x5a: hongwainum=6;break; // 6
case 0x42: hongwainum=7;break; // 7
case 0x52: hongwainum=8;break; // 8
case 0x4a: hongwainum=9;break; // 9
default: hongwainum=33;break;
}
if(hongwainum!=33)
{
beep();
hongwaiflag=1;
}
EX0=1;
return;
}
求大神帮我看看这段程序是如何实现解码接收的