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

📄 irc_000.c

📁 红外遥控器解码
💻 C
字号:
  #include<stc89c51rc_rd+.h>
  #define uchar unsigned char
  #define uint  unsigned int
  #define irc    P1 
  #define disp_data P2
  #define t_3ms5 0x0c
  #define t_1ms  0x03
 
unsigned char seg_bcd[] = {0x7e,0x48,0xbc,0xb6,0xd2,0xe6,0xee,0x38,0xFe,0xf2,   
                           };// 0--9
uchar get_code[4] = {0} ;
uchar tms[20]={0};
uchar  timer;
void UartInit();
void UartSendChar(unsigned char ch);
void delay(uint time)    //10ms--10000
{
 while(time--);
}

void set_timer()
{     
 TH0=0;      
 TL0=0;
 TR0=1;
}

void disp(dat)
{
  switch (dat)
    {case 0x1b:dat=10;break;
	 case 0x1f:dat=11;break;
	 case 0x1e:dat=12;break;
	 case 0x1a:dat=13;break;
	 default:break;
	}
  disp_data=seg_bcd[dat];	  
}
			  
uchar get_num()
{ uchar i,j,rd,dat=0;
  for(j=0;j<4;j++)
  { for(i=8;i>0;i--)
	 {
	  dat>>=1; 
	  do
      rd=irc;
      while(!(rd&0x04));	//	wait high
	  set_timer();		   //检测高电平时间
	  do
      rd=irc;
      while(rd&0x04);	//	wait low
	  TR0=0;
      timer=TH0;
	  if(timer>t_1ms)dat=dat|0x80;
      else dat=dat&0x7f;  	  
	  }
   get_code[j]=dat;
   }
return(get_code[2]);    
}

void main()
{
uchar rd;
UartInit();
 P2=0x00;
 P1=0xef;
 disp(5);
 TMOD=0x01;//T0选择方式一
judge: 
 do	
 rd=P1;
 while(rd&0x04); 	//wait low
 delay(100);
 rd=P1;
 if(rd&0x04)goto judge; //xiao dou
 do
 rd=irc;
 while(!(rd&0x04));	 //wait high
 set_timer();
 do
 rd=irc;
 while(rd&0x04);	 //wait low
 TR0=0;
 timer=TH0;
 if(timer<t_3ms5){delay(2000);goto judge;}//连续按下,重复标志
 rd=get_num();
 disp(rd);
 UartSendChar(rd);
 goto judge; 
}
/************************************************************
* Name: UartInit
* Func:
*  串行通信初始化
* Para: 
*  uchar ch: 发送的字符
* Return: None
***********************************************************/
void UartInit()
{
 SCON  = 0x50;          // SCON: serail mode 1, 8-bit UART
    TMOD |= 0x20;       // TMOD: timer 1, mode 2, 8-bit reload 
    PCON |= 0x80;       // SMOD="1"; 
    TH1   = 0xFA;       // Baud:9600  fosc="11".0592MHz 
 TL1   = 0xFA;
    IE   |= 0x90;       // 使能串行中断
 
    TR1   = 1;          // 启动TIMER1
 
}
  /************************************************************
 * Name: UartSendChar
 * Func:
 *  向串口发送一个字符
 * Para: 
 *  uchar ch: 发送的字符
 * Return: None
 ***********************************************************/
void UartSendChar(unsigned char ch)
{
    SBUF = ch;
    while(TI==0);
    TI=0;
}
					   

⌨️ 快捷键说明

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