📄 hongwai.c
字号:
//--------------------------------------------------
// 外部中断1服务程序
// 即红外识别程序
//--------------------------------------------------
#include "sfr.h"
#include "port.h"
//--------------------------------------------------
extern bit Ready;
extern enum State IRstate;
//--------------------------------------------------
void IRint() interrupt 2
{
static unchar count = 0;
static unchar recevier[9] = {0,0,0,0,0,0,0,0,0};
static unchar temp = 0;
static unchar bits = 1;
static unchar i = 0;
unint time = 0;
count++;
if( count >= 3 )
{
if( count == 3 )
{
TL1 = 0; // 第一个下降沿使能Timer1
TH1 = 0;
TR1 = 1;
}
else
{
TR1 = 0; // 禁止Timer1,准备Timer1的值
time = TH1;
time = ( time << 8 ) + TL1; // 读TIEMR1的值,看此电平的时间为多少
TL1 = 0;
TH1 = 0;
TR1 = 1;
if( time > 50 )
{
if ( ( time > 0x0460 ) && ( time < 0x0490 ) ) // 说明收到的此位为1
{
temp |= bits;
}
bits = bits << 1;
}
if( bits == 0 ) // 收到一个字节的数据了
{
recevier[i] = temp;
temp = 0;
bits = 1;
i++;
if( i == 9 ) //按一次按键产生的数据都已经收到
{
i = 0;
count = 0;
Ready = 1;
recevier[1] = recevier[1] & 0xF0;
if( recevier[0] == 0xA5 )
{
switch ( recevier[1] )
{
case 0x00: // 按下的是开关键
IRstate = IR_stop;
break;
case 0x80: // 按下的是开关键
IRstate = IR_start;
break;
case 0xC0: // 按下的是风速键
if( recevier[5] == 0x03 )
{
IRstate = IR_low; // 低风档
}
else if( recevier[5] == 0x01 )
{
IRstate = IR_middle; // 中风档
}
else if( recevier[5] == 0x02 )
{
IRstate = IR_large; // 高风档
}
else
{
IRstate = IR_error;
}
break;
case 0x40: // 按下的是模式键
if( recevier[6] == 0x04 )
{
IRstate = IR_sleep; // 睡眠模式
}
else if( recevier[6] == 0x02 )
{
IRstate = IR_clever; // 聪明模式
}
else if( recevier[6] == 0x06 )
{
IRstate = IR_simple; // 普通无模式
}
else
{
IRstate = IR_error;
}
break;
default:
IRstate = IR_error; // 收到误码
break;
}
}
else
{
IRstate = IR_error; // 收到误码
}
}
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -