⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 投影仪红外遥控解码C语言程序
💻 C
字号:
#include "STC89C51RC.H"
#include "Mini51B.H"

sbit DQ  = P4^3;
sbit SPK = P1^0;

unsigned char irm_code;
unsigned char code ledmap[]=    //共阴LED数码管译码表
{	
	0x3f,0x06,0x5b,0x4f,0x66,	//0,1,2,3,4,
	0x6d,0x7d,0x07,0x7f,0x6f,	//5,6,7,8,9,		
	0x77,0x7C,0x39,0x5E,0x79,	//A,b,C,d,E,
	0x71,						//F,
};

void delay(unsigned int t)
{			   
	while(t--);	
}
void Sound(void)
{
	SPK = 0;
	delay(10000);
	SPK = 1;
}

//STC单片机特有的外部中断INT2实现红外解码
//解码结果由数据缓冲区返回
void IRMint(void) interrupt 6
{		
	unsigned int temp;
	unsigned char i,temp_buff[2];

	EA = 0;/*解码过程禁止其它中断发生*/
	temp = 0;
	while(!DQ) if(temp++>0x1000) goto return_main;//防止意外死机	
	if (temp < 0x0400) goto return_main;//Max=0x0457
	/*以上完成引导码9ms的低电平检测*/
	temp = 0;
	while(DQ) if(temp++>0x1000)goto return_main;
	if (temp < 0x0180) goto return_main;//Max=0x0227
	/*以上完成引导码4.5ms的高电平检测*/
	for(i=0;i<16;i++)//跳过2字节引导码
	{
		temp = 0;
		while(!DQ)if(temp++>0x1000) goto return_main;//通过编码低电平
		temp = 0;
		while(DQ) if(temp++>0x1000) goto return_main;
	}

    /*有效字节*/
	for(i=0;i<8;i++)
	{ 
		temp_buff[0]<<=1;
		temp = 0;
		while(!DQ)if(temp++>0x1000) goto return_main;//通过编码低电平
		temp = 0;
		while(DQ) if(temp++>0x1000) goto return_main;
		if(temp > 0x0080) temp_buff[0] |= 0x01;
	}

    /*校验字节*/
	for(i=0;i<8;i++)
	{ 
		temp_buff[1]<<=1;
		temp = 0;
		while(!DQ)if(temp++>0x1000) goto return_main;//通过编码低电平
		temp = 0;
		while(DQ) if(temp++>0x1000) goto return_main;
		if(temp > 0x0080) temp_buff[1] |= 0x01;
	}

    /*校验*/
	if (temp_buff[0] == ~temp_buff[1]) 
	{
		irm_code = temp_buff[0];
		Sound();
	}	
	return_main:EA = 1;
}

void main()
{
	unsigned char temp;
	EA = 1;
	IT2 = 1;//下降沿中断
	EX2 = 1;
	
	seg1 = 0xff;//熄灭		   				 		
	while(1)
	{				
		if(irm_code!=temp)	
		{
			temp = irm_code;
			seg2 = ~ledmap[temp/100];
			seg3 = ~ledmap[temp/10%10];
			seg4 = ~ledmap[temp%10];			
		}				
	}
} 	

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -