📄 ir.c
字号:
#include <REG52.H>
unsigned char gIrArr[6];
#define TIME_0_00MS 0x0000
#define TIME_1_00MS 0x039a
#define TIME_1_13MS 0x0480
#define TIME_2_00MS 0x0733
#define TIME_2_50MS 0x0900
#define TIME_13_2MS 0x2ecd
#define TIME_20_0MS 0x47ff
#define TIME1_LOAD (0xffff - TIME_20_0MS)
bit running;
long Irbuf;
unsigned char Irdat;
bit Irok;
void int1_isr(void) interrupt 2 //遥控使用外部中断0,接P3.2口
{
unsigned int timer;
static char x=0x03;
TR0 = 0;
timer = ((TH0 << 8) | TL0) - TIME1_LOAD;
TH0 = TIME1_LOAD >> 8;
TL0 = TIME1_LOAD & 0xff;
x=(x ^ 0xff);
*((char xdata *)0xd000)=x;
TR0=1;
if (timer > TIME_1_00MS && timer < TIME_1_13MS) //data 0
Irbuf = (Irbuf << 1) & 0xfffffffe;
else if (timer > TIME_2_00MS && timer < TIME_2_50MS) //data 1
Irbuf = (Irbuf << 1) | 0x00000001;
else if (timer == TIME_0_00MS || timer > TIME_13_2MS)
Irbuf = 0x0000;
else
;
if (((Irbuf >> 8) & 0xff) == ((~(Irbuf >> 0)) & 0xff))
{
Irdat = (Irbuf>>8) & 0xff;
gIrArr[0]=(Irdat / 100) + 0x30;
gIrArr[1]=((Irdat % 100) / 10) + 0x30;
gIrArr[2]=(Irdat % 10) +0x30;
gIrArr[3]='\n';
gIrArr[4]='\r';
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -