原创 SAA3010红外解码

2010-6-13 17:24 2820 5 5 分类: MCU/ 嵌入式

SAA3010的红外解码。

SAA3010是遥控器中常用的红外编码芯片,采用的是PHILIPS的RC-5协议。一个全码包括 2位起始位+1位控制位+5位系统位+6位数据位.采用双相位编码发送。发送一位的典型事件是1.788ms。


下面是解码的源程序,液晶的程序在附件中

#include <reg52.h>https://static.assets-stash.eet-china.com/album/old-resources/2010/6/13/2abf4b6d-d40e-4260-acf5-9b3cdd0a0d02.zip
#include <lcm12864.h>

unsigned char int_num,byte_num,hwcode[3],code_num,i,one_bit,a,temp1;
unsigned char a1,a2,a3,a4,code_data;

sbit OUT = P3^3;

void Init_Int()
{
EA = 1;
EX1 = 1;
IT1 = 1;
TMOD = 0x11;
}

void Int1() interrupt 2
{
int_num++;
if(int_num==2) //第二次进入中断时开启定时器,开始采样
{
int_num = 0;
EX1 = 0;
TH1= 0xfe;
TL1 = 0x8f;
ET1 = 1;
byte_num = 0;
code_num = 0;
TR1 = 1;
}
}

void Timer2() interrupt 3
{
TH1 = 0xfd;
TL1 = 0x1f;
temp1++;
if(temp1>=4)
{
temp1 = 4;
if(byte_num<3) //还没有采集到三个字节
{
if(code_num<8)
{
code_num++;
hwcode[byte_num] <<= 1;
hwcode[byte_num] |= OUT;
if(code_num>=8)
{
byte_num++;
code_num = 0;
}
}
}
else //采集到三个字节
{
temp1 = 0;
TR1 = 0;
ET1 = 0;
if (((hwcode[0]&0x3f)==0x15) && ((hwcode[1]&0xf0)==0x50)) //判断系统位是否为00000
{
LCM12864_wr_Cmd(0x80);
a = hwcode[0]; //显示第一个字节
for(i=0;i<8;i++)
{
one_bit = (a&0x80)>>7;
if(one_bit==1)
one_bit = 0;
else
one_bit = 1;
LCM12864_wr_Byte(one_bit+0x30);
a <<= 1;
}
LCM12864_wr_Cmd(0x90);
a = hwcode[1]; //显示第二个字节
for(i=0;i<8;i++)
{
one_bit = (a&0x80)>>7;
if(one_bit==1)
one_bit = 0;
else
one_bit = 1;
LCM12864_wr_Byte(one_bit+0x30);
a <<= 1;
}
LCM12864_wr_Cmd(0x88);
a = hwcode[2]; //显示第三个字节
for(i=0;i<8;i++)
{
one_bit = (a&0x80)>>7;
if(one_bit==1)
one_bit = 0;
else
one_bit = 1;
LCM12864_wr_Byte(one_bit+0x30);
a <<= 1;
}

code_data = 0; //从第二个第三个字节中提取编码信息
a1 = (hwcode[2]&0x80)>>7;
a2 = (hwcode[2]&0x20)>>5;
a3 = (hwcode[2]&0x08)>>3;
a4 = (hwcode[2]&0x02)>>1;
code_data = a1<<3|a2<<2|a3<<1|a4;
a1 = (hwcode[1]&0x80)>>7;
a2 = (hwcode[1]&0x20)>>5;
a3 = (hwcode[1]&0x08)>>3;
a4 = (hwcode[1]&0x02)>>1;

code_data = code_data|a1<<7|a2<<6|a3<<5|a4<<4; //将提取的编码合成一个字节

code_data = code_data&0x3f; //数据码只有六位

LCM12864_wr_Cmd(0x9f);
LCM12864_wr_Byte(code_data/10+0x30);
LCM12864_wr_Byte(code_data%10+0x30);
}
EX1 = 1;
}
}
}

void main()
{
Init_12864Word();
LCM12864_wr_String(4,1,"红外测试");
Init_Int();
while(1);
}






PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
我要评论
0
5
关闭 站长推荐上一条 /3 下一条