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

📄 dira_func.c

📁 8051单片机结合BU2614的PLL程序
💻 C
字号:
#include "c8051f020.h"
#include "lcd.h"
#include "digital_radio.h"
#include "string.h"

#define T_3MS 0xf533	//定时器延时3ms(system clock=22118400/2,定时器12分频)
#define T_0_8MS 0xfd1f	//定时器延时0.8ms(system clock=22118400/2,定时器12分频)

/*SET 16bit REGISTER*/
sfr16 TMR3   = 0x94;
sfr16 TMR3RL = 0x92;

sbit P37=P3^7;

static bit Head_ok=0,Got=0;	 //head_ok=1:帧头正确,got=1:收齐四字节

static unsigned char val[4]=0;//四字节的红外键值


void Timer3_Init()
{
    TMR3CN   &=0xfb;	//关定时器3
    TMR3RL    = T_3MS;  //延时3ms
    TMR3      = T_3MS;
}

unsigned char   Wait_infrared()
{		
		unsigned char  keyvalue;
	    
      while(!Got);
      if(val[2]+val[3]==0xff)
      keyvalue=val[2];
      Got=0;
		
		return(keyvalue);	
}

/*即时输出并取出按键的实值*/
/* void Get_Letter(unsigned char x,unsigned char y,unsigned char *letter)
{
	unsigned char m,ascii,temp;
	unsigned char *let=letter;
	for(m=0;m<7;m++) letter[m]=0;
	clear1line(x);
	LCD_Goto(x,y);
	Delay1us(40);
	for(m=0;m<5;m++)
	{
			
			temp=Wait_infrared();

			ascii=tbel[temp];		
		   	if(temp==0x15)
			{
			 clear1line(x);
			 let-=1;
			 *let='\0';
			 LCD_Printf(x, y,letter);
			}
			else if(temp==0x14)	
			{
				*let='\0';
				break;
			}
			else if(ascii!=0x21)			
			{
			     clear1line(x);
				 *let=ascii;
			     LCD_Printf(x, y,letter);				//向LCD发送
				 let++;
			 }
	}
 } */


void clear1line(unsigned char j)
{
 unsigned char i;
 LCD_Goto(j,1);
 for(i=0;i<16;i++) LCD_WriteData(0x20);
 Delay1ms(1);
}

void Radio_Send(unsigned int data)
{
 unsigned temp;
  
}


void ex_interrupt() interrupt 19	 //下降沿中断,收到低电平开始 
{

if(!Head_ok)
 {
 EIE2&=0xdf;//关中断7
  P3IF&=0x7f;//清中断7的中断标志
  Timer3_Init();//定时器3初始化
  TMR3CN|=0x04;  //开定时器3
  }
 else 
 {
  while(P37==0&&TMR3CN<0x80);  //等待变高
  if(TMR3CN<0x80)
  {
   P3IF&=0x7f;//清中断7的中断标志 
   TMR3      = T_0_8MS;//延时0.8ms
   TMR3CN|=0x04;  //开定时器3
  }
 }
}

void T3_inter() interrupt 14
{
  static unsigned char i=0,n=0;
  static bit h=0; 
  unsigned int v;
  TMR3CN&=0x7f;  //清中断标志

 if(Head_ok==0&&h==0&&P37==0) h=1;
 else if(Head_ok==0&&h==1&&P37==1)
 {
  EIE2|=0x20; //开中断7
  TMR3CN&=0xfb;	//关定时器3
  h=0;Head_ok=1;return;
 }
 else if(Head_ok)
   {
      TMR3CN&=0xfb;	//关定时器3
      n=i++/8;
    if(P37) 
        {
         val[n]=val[n]>>1;
         val[n]|=0x80;
        }
    else 
         val[n]=val[n]>>1;
//       n=++i/8;
    if(i==32)
       {
        i=0;n=0;Head_ok=0;
        EIE2&=0xdf;//关中断7
        for(v=0;v<60000;v++);	 //避开重复码
        EIE2|=0x20; //开中断7
        Got=1;
       }
    } 
 else 		//还原为最原始状态
 {
  EIE2|=0x20;//开中断7
  Timer3_Init();
  h=0;Got=0;Head_ok=0;
 } 
}

⌨️ 快捷键说明

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