51单片机——在数码管上显示红外遥控器按钮的码值

/*在数码管上显示红外遥控器按钮的码值*/

#include 
#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 //此处为晶振11.0592的取值,用其他晶振频率时,要改变Imax、Imin、Inum1、Inum2、Inum3的取值
#define Imin 8000 
#define Inum1 1450
#define Inum2 700
#define Inum3 3000
unsigned char Im[4]={0x00,0x00,0x00,0x00};
uchar show[2]={0,0};
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()
{
	dula=0;
	P0=table[show[0]];
	dula=1;
	dula=0;
	wela=0;
	P0=0xfe;
	wela=1;
	wela=0;
	delay(5);
	P0=table[show[1]];
	dula=1;
	dula=0;
	P0=0xfd;
	wela=1;
	wela=0;
	delay(5);
}

//ÍⲿÖжϽâÂë³ÌÐò

void intersvr1(void) interrupt 2 using 1
{
	Tc=TH0*256+TL0; //ÌáÈ¡ÖжÏʱ¼ä¼ä¸ôʱ³¤
	TH0=0;
	TL0=0; //¶¨Ê±ÖжÏÖØÐÂÖÃÁã
	if((Tc>Imin)&&(TcInum1&&Tc>1|0x80; m++;
		}
			if(Tc>Inum2&&Tc>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;
	EA=1;
	IT1=1;EX1=1;
	TMOD=0x11;
	TH0=0;TL0=0;
	TR0=1;//ET0=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();
		}
	}
}

你可能感兴趣的:(单片机)