高级会员
主题
回帖0
积分4434
阅读权限30
注册时间2010-5-12
最后登录1970-1-1
在线时间 小时
|
解码程序段不怎么好,上一个我做的,希望能起到抛砖引玉的作用,多多交流……
#include<regx52.h>
#include<_1602.h>
#define uchar unsigned char
#define uint unsigned int
#define M110592
#ifdef M110592
#define guide_h 48
#define high_h 8
#define low_h 4
#define mask 0xfc
#else
#define guide_h 105
#define high_h 17
#define low_h 8
#define mask 0xf8
#endif
bit guide_flag=0;
uchar code aa[]="0123456789ABCDEF";
uchar xxh,nums,r_data,rf_ram[4], temp ,numss=0;
void delay(uchar mm)
{
while(mm--);
}
void test(uchar num)
{
wdat(aa[num /16]);
wdat(aa[num%16]);
}
void main(void)
{
SP=125;
TMOD = 0x12; //TMOD: GATE C/T M1 M0 GATE C/T M1 M0
TH1=0;
TL1=0;
TR1=0; //TCON: TF1 TR1 TF0 TR0 IE1 IT1 IE0 IT0
ET1=1;
wcmd(0x38); //16*2显示,5*7点阵,8位数据
wcmd(0x0c); //显示开,关光标
wcmd(0x06); //移动光标
wcmd(0x01); //清除LCD的显示内容
EX0=1; //IE : EA - ET2 ES ET1 EX1 ET0 EX0
IT0 = 1;
EA=1; // IE=0x89;
while(1)
{
position(0);
test(numss);
wdat('*');
test(rf_ram[0]);
wdat(' ');
test(rf_ram[1]);
wdat(' ');
test(rf_ram[2]);
wdat(' ');
test(rf_ram[3]);
}
}
void decode(void) interrupt 0
{
xxh=TH1;
TH1=0;
TR1=1;
IE0=0;
if(guide_flag==0)
{
if((xxh & mask)==(guide_h & mask))//引导码
{
guide_flag=1;
nums=0;
r_data=0;
}
}
else
{
nums += 1;
if((xxh & mask)==(high_h & mask))
{
r_data >>= 1;
r_data |= 0x80;
}
else if((xxh & mask)==(low_h & mask))
r_data >>= 1;
else
{
nums=0;
guide_flag=0;
r_data=0;
TH1=0;
}
if((nums % 8 )==0)
{
temp=nums / 8 - 1;
rf_ram[temp]=r_data;
r_data=0;
if(temp==3)
{
//************************
//防干扰,关闭外部中断0以跳过一段时间
//从eeprom读取用户码和键值码 以消耗时间
TR1=0;TH1=0;
numss++;
guide_flag=0;
nums=0;
// if(rf_ram[2]==(~rf_ram[3]))//数据码与反码是否匹配
// r_decode_data=rf_ram[2];
}
}
}
IE0=0;
}
void timer1(void) interrupt 3
{
TR1=0;
TH1=0;
TL1=0;
IE0=0;
} |
|