#include <reg52.h>
#define uchar unsigned char
//sbit dula=P2^6;
//sbit wela=P2^7;
uchar code table[]={0x3f,0x06,0x5b,0x4f,0x66,0x6d,0x7d,0x07,0x7f,0x6f,0x77,0x7c,0x39,0x5e,0x79,0x71};
uchar f;
#define Imax 14000
#define Imin 8000
#define Inum1 1450
#define Inum2 500
#define Inum3 3000
unsigned char Im[4];
uchar show[2];
unsigned long m,Tc;
unsigned char IrOK;
void delay(uchar i)
{
uchar j,k;
for(j=i;j>0;j--)
for(k=125;k>0;k--);
}
void display()
{
P2=0xf8;
//dula=0;
P0=table[show[0]];
//dula=1;
//dula=0;
//wela=0;
//wela=1;
//wela=0;
delay(5);
P2=0xf9;
P0=table[show[1]];
//dula=1;
//dula=0;
//wela=1;
// wela=0;
delay(5);
}
//外部中断解码程序
void intersvr1(void) interrupt 2 using 1
{
Tc=TH0*256+TL0;
TH0=0;
TL0=0;
if((Tc>Imin)&&(Tc<Imax))
{
m=0;
f=1;
// return;
} //找到启始码
if(f==1)
{
if(Tc>Inum1&&Tc<Inum3)
{
Im[m/8]=Im[m/8]>>1|0x80; m++;
}
if(Tc>Inum2&&Tc<Inum1)
{
Im[m/8]=Im[m/8]>>1; m++; //取码
}
if(m==32)
{
m=0;
f=0;
if(Im[2]==~Im[3])
{
IrOK=1;
}
else IrOK=0; //取码完成后判断读码是否正确
}
//准备读下一码
}
}
/*演示主程序*/
void main(void)
{
unsigned int a;
m=0;
f=0;
IT1=1;
EX1=1;
TMOD=0x01;
TH0=0;
TL0=0;
EA=1;
//ET0=1;
//??????
TR0=1;
while(1)
{
if(IrOK==1)
{
show[1]=Im[2] & 0x0F; //取键码的低四位
show[0]=Im[2] >> 4;
IrOK=0;
}
for(a=100;a>0;a--)
{
display();
}
}
}
该程序T0中断ET0一打开红外解码显示就变得很不稳定,只有把它屏蔽了才可正常显示。
请问下着是什么原因??? |