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

📄 rem.c

📁 单片机键值测定程序
💻 C
字号:

#include "define.h"
#include "global.h"
#include <AT89X52.H>
#include <intrins.h>

extern void Initial_16311(void);
extern void Validate_Key(uchar,uchar);
//---------------------------------------------------------------------------
// Delay
//---------------------------------------------------------------------------
uchar REM_value;
bit BZ_rem;
uchar REM_add;

static void Delay100us(void)   //24MHz(LJMP:CLR A;MOV R7 A;INC A;CNJE R6 65)
{
   uchar data i;
   for(i=0; i<65; i++);
}

//------------------------------------------------------------------
void REM_KEY(void)
{
  uchar count, i, j;
  uchar aIRCodes[4]; //接收32位代码
  uchar bByte;//做数剧接收时的移位寄存器
	if(PIN_IR)return;
	// --------------- Leader signal (low 9ms + high 4.5 ms) -----------------
	for (count=0; !PIN_IR; count++) 
         Delay100us(); 	// 接收9mS的低电平头码;
	if ((count < 80) || (count > 100)) {
        BZ_rem=0;
        return;}	//判别是否是9mS,如果不是就反回;并清除标志变量。

	for (count=0; (PIN_IR) && (count < 54) ; count++) Delay100us(); //接收4.5ms的高电平信号。


		if ((count >= 19) && (count <= 24)) //如果连续按住了同一个按键则只发送开始码和结束码, low (9ms) , high (2.25), low (0.56)
		  {
			for (count=0; !PIN_IR ; count++) 
                Delay100us();
		           if ((count >= 4) && (count <= 7))
                      {
                       BZ_rem=1;
			    	   return;
		              }}
		
        else if ((count > 35) || (count < 54))//读遥控代码, logic 0 = low (0.56) + high (0.56), logic 1= low (0.56) + high (1.68)
        {	
        	for(i=0; i<4; i++)
             {
	           bByte = 0;
	            	for (j=0; j<8; j++)
                      {
			             for (count=0; (!PIN_IR); count++) 
                             Delay100us(); 		//经过底电平
		                        for (count=0; PIN_IR && (count < 30); count++) 
                                    Delay100us();
		            	            if (count == 0)
                                      {
			                            j--;
				                        continue; // 考虑有信号噪声
			                           }
			                  bByte >>= 1; // shift right one bit
			                  if (count >= 9)
                                 {  // bit=0 => count<9; bit=1 => count>9
				                    // > 0.9 ms==> logic 1
				                    // else ==> logic 0
			                    	if (count >= 30){  BZ_rem=0; return;  } // count>30 => error
			                     	bByte |= 0x80;
		                  	     }
		              }
		       aIRCodes[i] = bByte;
	         }
           }

//------------------
//	if (aIRCodes[0] != IR_CUSTOMER_CODE) return; 		// 测试用户码是否能对应
//	if ((aIRCodes[0]==0) && (aIRCodes[1]==0) && (aIRCodes[2]==0) && (aIRCodes[3]==0))
//      { 
//		BZ_rem=0;return;
//	  }
//	else 
//      {
		if (aIRCodes[2] == ~aIRCodes[3])
          {
			REM_value = aIRCodes[2];
			REM_add=aIRCodes[0];
			BZ_rem=1;//return;//"0x00"表示遥控用户码,"0x01"表示遥控键值,"0x02"表示16311键值.
		  }
//		else 
//		  {BZ_rem=0;return;}
//	   }
}

⌨️ 快捷键说明

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