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

📄 com_frontboard.c

📁 单片机为2051,带有数码管显示机顶盒前面板程序
💻 C
📖 第 1 页 / 共 2 页
字号:
#include "at89x051.h"

#define SYSTEM_CODE1 0x20
#define	SYSTEM_CODE2 0xDF

#define	REC_START_BYTE 0xe0
#define  RESET_ERROR_CONDITION_TIME 0x20
#define	OK 0xF3
#define	ER 0xF4

#define INI_VECTORLo   0x00
#define INI_VECTORHi   0x00
#define POLYNOMIALHi   0x80
#define POLYNOMIALLo   0x05

#define  ILEN  12
#define  OLEN  4

///unsigned char rec_display[4]={0x7c,0x5c,0x5c,0x78};
unsigned char rec_display[4]={0xff,0xff,0xff,0xff};
unsigned char rec_info[7]={0,0,0,0,0,0,0};
unsigned char rec_info_count=0;
unsigned char rec_temp_data;
unsigned char rec_time_count=0;
bit rec_time_count_sw=0;
bit rec_first_start_byte_flag=1;
bit rec_sw=0;

idata unsigned char  outbuf[OLEN];
idata unsigned char  inbuf[ILEN];  
unsigned char idata  *outlast=outbuf;
unsigned char idata  *putlast=outbuf;
unsigned char idata  *inlast=inbuf;
unsigned char idata  *getlast=inbuf;
bit  outbufsign;
bit  outbufsign0;
bit  inbufsign;
bit  inbufful;
bit  first;
bit  standby=1;
bit  continue_txd_switch=1;

unsigned char  output_remote_count,remote_count,timeout_count=0;

unsigned char	sys1_bit_count,sys2_bit_count,com_bit_count,n_com_bit_count;
typedef struct {
   unsigned char sys1_code;
   unsigned char sys2_code;
   unsigned char comm_code;
   unsigned char no_comm_code;
 } REV_CODE;  
REV_CODE recv_code;

unsigned char code output_key[]={0x5f,//enter
                                 0x04,//menue
						               0x12,//standby
                                 0x02,//ch+
   					               0x01,//ch-
						               0x05,//vol+
						               0x0c,//vol-
											0x49,//exit
                                 0xf1};//for loader

unsigned char output_remote_count;
/*
unsigned char code output_remote_info[]={0x12,//0x01//standby
                                    0x1b,//0x02//静音
                                    0x15,//0x03//help
                                    0x16,//0x04//制式
                                    0x17,//0x05//图象静止
                                    0x5e,//0x06//1
                                    0x0d,//0x07//2
                                    0x11,//0x08//3
                                    0x09,//0x09//4
                                    0x06,//0x0a//5
                                    0x55,//0x0b//6
                                    0x57,//0x0c//7
                                    0x56,//0x0d//8
                                    0x13,//0x0e//9
                                    0x48,//0x0f//屏显//频道信息
                                    0x4f,//0x10//0
                                    0x02,//0x11//ch+
                                    0x0c,//0x12//vol-
                                    0x04,//0x13//menu
                                    0x05,//0x14//vol+
                                    0x01,//0x15//ch-
                                    0x49,//0x16//EXIT
                                    0x5f,//0x17//enter
                                    0x42,//0x18//EPG//节目信息表
                                    0x43,//0x19//回上一节目
                                    0x0f,//0x1a//声道切换
                                    0x1e,//0x1b//F1
                                    0x1d,//0x1c//F2
                                    0x1c,//0x1d//F3
                                    0x18,//0x1e//page_up
                                    0x4c};//0x1f//page_down
*/
unsigned char code output_remote_info[]={0x12,//0x01//standby
                                    0x1b,//0x02//静音
                                    0x48,//0x15,//0x03//help
                                    0x4f,//0x16,//0x04//制式
                                    0x17,//0x05//图象静止
                                    0x5e,//0x06//1
                                    0x0d,//0x07//2
                                    0x11,//0x08//3
                                    0x09,//0x09//4
                                    0x06,//0x0a//5
                                    0x55,//0x0b//6
                                    0x57,//0x0c//7
                                    0x56,//0x0d//8
                                    0x13,//0x0e//9
                                    0x4c,//0x48,//0x0f//屏显//频道信息
                                    0x18,//0x4f,//0x10//0
                                    0x02,//0x11//ch+
                                    0x0c,//0x12//vol-
                                    0x5f,//0x04,//0x13//menu
                                    0x05,//0x14//vol+
                                    0x01,//0x15//ch-
                                    0x49,//0x16//EXIT
                                    0x04,//0x5f,//0x17//enter
                                    0x43,//0x42,//0x18//EPG//节目信息表
                                    0x1c,//0x43,//0x19//回上一节目
                                    0x42,//0x0f,//0x1a//声道切换
                                    0x1e,//0x1b//F1
                                    0x0f,//0x1d,//0x1c//F2
                                    0x1d,//0x1d//F3
                                    0x15,//0x18,//0x1e//page_up
                                    0x16/*0x4c*/};//0x1f//page_down

unsigned char code rec_remote_info[]={0x12,//0x01//standby
                                    0x1b,//0x02//静音
                                    0x15,//0x03//help
                                    0x16,//0x04//制式
                                    0x17,//0x05//图象静止
                                    0x5e,//0x06//1
                                    0x0d,//0x07//2
                                    0x11,//0x08//3
                                    0x09,//0x09//4
                                    0x06,//0x0a//5
                                    0x55,//0x0b//6
                                    0x57,//0x0c//7
                                    0x56,//0x0d//8
                                    0x13,//0x0e//9
                                    0x48,//0x0f//屏显//频道信息
                                    0x4f,//0x10//0
                                    0x02,//0x11//ch+
                                    0x0c,//0x12//vol-
                                    0x04,//0x13//menu
                                    0x05,//0x14//vol+
                                    0x01,//0x15//ch-
                                    0x49,//0x16//EXIT
                                    0x5f,//0x17//enter
                                    0x42,//0x18//EPG//节目信息表
                                    0x43,//0x19//回上一节目
                                    0x0f,//0x1a//声道切换
                                    0x1e,//0x1b//F1
                                    0x1d,//0x1c//F2
                                    0x1c,//0x1d//F3
                                    0x18,//0x1e//page_up
                                    0x4c};//0x1f//page_down
//************************************************************************
//函数原形
void display(void);
void delay_display(unsigned int count);
void display_for_standby(void);
void rec_data(void);
void rec_data_process(void);
//void putstring(unsigned char  *puts);
unsigned char getbyte (void);
unsigned short get_crc16(unsigned char *data_blk_ptr,unsigned char data_blk_size);
void putbyte(char c);
void init(void);
void delay(unsigned int parameter1,unsigned int parameter2);
void fun_shift_one_bit(bit data_out);
unsigned char key_push();
unsigned char key_assignments();
void reset_rec_condition(void);
void reset_remote_condition(void);
///////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////
//reset遥控接受参数
void reset_remote_condition(void)
{
  first=1; 
  n_com_bit_count=0;
  com_bit_count=0;
  sys1_bit_count=0;
  sys2_bit_count=0;
  recv_code.sys1_code=0;
  recv_code.sys2_code=0;
  recv_code.comm_code=0;
  recv_code.no_comm_code=0;
}
//系统初始化
void init(void)
{
  IE=0x00;		
  TMOD=0x21;
  IP=0x00;		
  TCON=0x01;
  PCON=0x00;
  SCON=0x50;
  TH1=0xfd;
  TL1=0xe8;
  TR1=1;
  P3_7=1;
  P3_4=0;
  remote_count=0;
  reset_remote_condition();
  ES=1;
  PS=1;
  PX0=0;
  EX0=1;
  ET0=1;
  PT0=1;
  EA=1;
}
//延时函数
void delay(unsigned int parameter1,unsigned int parameter2)
{
    unsigned int infield,exospore;
    for(infield=0;infield<=parameter1;infield++)
        {
            for(exospore=0;exospore<=parameter2;exospore++);
        }	
}
//串口中断服务程序
serial () interrupt 4  using 1
{   
    if (TI ) 
    { TI = 0;
  		if (outbufsign)              
    	  	{SBUF=*outlast;
    	    outlast++;
    		 if (outlast==outbuf+OLEN) outlast=outbuf;
    		 if (putlast==outlast) outbufsign=0;
     	    } 
   	 else outbufsign0=0;
    }
    if (RI)  
    {  RI = 0;	
	    if(!inbufful)
    	   {
			 rec_temp_data=SBUF;
    	    *inlast= rec_temp_data;
    	    inlast++;
          inbufsign=1; 
        	 if (inlast==inbuf+ILEN) inlast=inbuf;
    	    if (inlast==getlast)  	 inbufful=1;
    	    rec_data();
    	   }		 
    }
}

//外部中断0服务程序
void ex0_int(void)  interrupt 0 
{
 unsigned int counter;
 unsigned char remote_assignment;
 TR0=0;ET0=0;
 if(first==1) 
  {
   TH0=-(65536/256);
   TL0=-(65536%256);
   first=0;
   TR0=1;ET0=1;
   counter=TH0*256+TL0;   
  }
 else {
        counter=TH0*256+TL0; 
        if(counter>11520) //非连续按键
         { TH0=-(65536/256);
           TL0=-(65536%256);
           TR0=1;ET0=1;
           return;
         }
        else if(counter>7373){//连续按键
		  	if(output_remote_count<0x1f)
           {if((output_remote_info[output_remote_count]==0x0c)||(output_remote_info[output_remote_count]==0x05)
				||(output_remote_info[output_remote_count]==0x18)||(output_remote_info[output_remote_count]==0x4c)){
					if(continue_txd_switch==1){	
					      if(remote_count>=4){
						   putbyte(output_remote_info[output_remote_count]);
							remote_count=0;
							reset_remote_condition();
							timeout_count=0;
							}
						else remote_count++;
						}
					}
				 }
				else{reset_remote_condition();}
		  		}
	      else{   
	        if(sys1_bit_count<8)
	          {if(counter>1548)
	           recv_code.sys1_code= recv_code.sys1_code|(0x01<<sys1_bit_count);
	           sys1_bit_count++;}
	        else if(sys2_bit_count<8)
	          {if(counter>1548)
	           recv_code.sys2_code= recv_code.sys2_code|(0x01<<sys2_bit_count);
	           sys2_bit_count++;}   
	        else if(com_bit_count<8)
	          {if(counter>1548)
	           recv_code.comm_code= recv_code.comm_code|(0x01<<com_bit_count);
	           com_bit_count++;} 
	        else if(n_com_bit_count<8)
	          {if(counter>1548)
	           recv_code.no_comm_code= recv_code.no_comm_code|(0x01<<n_com_bit_count);
	           n_com_bit_count++;}
           if(n_com_bit_count>=8)
	         { if((recv_code.sys1_code==SYSTEM_CODE1)&&(recv_code.sys2_code==SYSTEM_CODE2)&&(recv_code.comm_code==~recv_code.no_comm_code))
	             {
					remote_assignment=recv_code.comm_code;
               for(output_remote_count=0;output_remote_count<=0x1f;)
               {if(rec_remote_info[output_remote_count]==remote_assignment) break;output_remote_count++;}
				  if(output_remote_info[output_remote_count]==0x12)//STANDBY键处理
			  	   {standby=~standby;P3_7=standby; 
					putbyte(output_remote_info[output_remote_count]);
					display_for_standby();}
		        else{if(output_remote_count<0x1f){putbyte(output_remote_info[output_remote_count]);}}

⌨️ 快捷键说明

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