📄 irm.c
字号:
#include "osc.h"
#include "irm.h"
#include "number.h"
#include "common.h"
unsigned char irm_code;//红外解码键值返回全局变量
bit flag ;// 上一位编码位
void extern2_init(void)
{
EA = 1;
IT2 = 1;//下降沿中断
EX2 = 1;
}
static unsigned char check_bit(unsigned char bit_num)
{
//最大检测7位
unsigned char irm_code0 = 0;
unsigned char i ;
unsigned int count ;
#define ERROR 0x10;
for(i=0;i<bit_num;i++)
{
count = 0 ;
irm_code0 = irm_code0<<1 ;
if(flag)
{
while(IRM_DQ)if(count++>10000) return ERROR;
if(count>150)
{
flag = 0 ;// 结束码为 10
}
else
{
flag = 1 ;// 结束码为 01
irm_code0 |= 0x01;
while(!IRM_DQ)if(count++>10000) return ERROR;
}
}
else // 结束码为 10
{
while(!IRM_DQ)if(count++>10000) return ERROR;
if(count>150)
{
flag = 1 ;// 结束码为 01
irm_code0 |= 0x01;
}
else
{
flag = 0 ;// 结束码为 10
while(IRM_DQ)if(count++>10000) return ERROR;
}
}
}
return irm_code0 ; //解码成功 !!
}
//STC单片机特有的外部中断INT2实现红外解码
//解码结果由数据缓冲区返回
void IRMint(void) interrupt 6
{
unsigned int count;
unsigned char temp_code[2];
EA = 0;/*解码过程禁止其它中断发生*/
IRM_DQ = 1 ;
/*跳过1.5bit 起始码*/
{
count = 0;
while(!IRM_DQ)if(count++>1000) goto return_main;
count = 0;
while(IRM_DQ)if(count++>1000) goto return_main;
}
/*跳过1bit控制码和5bit用户码*/
{
flag = 0 ; //起始码以10结束
temp_code[0] = check_bit(6);
}
/*数据码*/
temp_code[1] = check_bit(6);
irm_code = temp_code[1] ; //返回键值
IE2 = 0 ;
EX2 = 0;
return_main:
EA = 1;
}
/*按键扫描*/
void key_scan(void)
{
unsigned int code timeH [] = {111,254,253,248,241,183};//{50,5000,2500,1000,500,100};
unsigned int code timeL [] = {255,143, 30,204,153,255};//{50,5000,2500,1000,500,100};
if(irm_code!=0) {
switch (irm_code)
{
case 30: acdc_flag ^= 0x01; break;
case 31: run_flag ^= 0x01; break;
case 34: if(pointxA > 0 ) pointxA--; break;
case 35: if(pointxA < WIDTH-2) pointxA++; break;
case 42: if(pointxB > 0 ) pointxB--; break;
case 43: if(pointxB < WIDTH-2) pointxB++; break;
case 45: if(pointyA > ZEROY-HEIGHT+1) pointyA--; break;
case 44: if(pointyA < ZEROY-2 ) pointyA++; break;
case 47: if(pointyB > ZEROY-HEIGHT+1) pointyB--; break;
case 46: if(pointyB < ZEROY-2 ) pointyB++; break;
case 48: if(val_tdiv > 0) val_tdiv--; break;
case 49: if(val_tdiv < 4) val_tdiv++; break;
case 54: if(val_vdiv > 0) val_vdiv--; break;
case 58: if(val_vdiv < 5) val_vdiv++; break;
case 55: if(movx > -(WIDTH/2-1)) movx--; break;
case 56: if(movx < (WIDTH/2-1)) movx++; break;
case 63: if(movy > -(HEIGHT/2)) movy--; break;
case 57: if(movy < (HEIGHT/2)) movy++; break;
default: break;
}
RCAP2H = timeH[val_tdiv];
RCAP2L = timeL[val_tdiv];
irm_code=0;
BEEP_ON();
disp_vdiv();
disp_ypoint();
delay_ms(200);
BEEP_OFF();
delay(10000);
EX2 = 1;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -