📄 ir.c
字号:
#include <reg51.h>#include <intrins.h> // _nop() in the file .#include <stdio.h> // printf() in the file .#include <string.h>#include "78e65.h"#include "config.h"#include "tda7440d.h"#include <invx1828.h>#include <func_shi.h>#include "ext_globl.h"#include "ext_osd.h"#include "osd_vx1828.h"//*********************************************************// key define //*********************************************************sbit IR = P3^3;#define ir_customer 0x03fc//#define IR_CUSTOMER ir_customer#if _debug#define irkey_0 0x68#define irkey_1 0x30#define irkey_2 0xb0#define irkey_3 0x70#define irkey_4 0xf0#define irkey_5 0x08#define irkey_6 0x88#define irkey_7 0x48#define irkey_8 0xc8#define irkey_9 0xa8 #endif#define irkey_power 0x0#define irkey_menu 0x1a#define irkey_select 0x50#define irkey_source 0xfa#define irkey_mute 0x40#define irkey_up 0x9a#define irkey_down 0x5a#define irkey_left 0xba#define irkey_right 0x7a#define irkey_vol_add 0xea #define irkey_vol_sub 0x6a#define irkey_bri_add 0xaa#define irkey_bri_sub 0x2a//------------------------------------------------#define irkey_isp 0x3a#define irtest 0x0a//------------------------------------------------//***************************************************************//define IR program's flag . used in func_ir.cbit irpower_flag = 0; // IR Power Button Active flagbit irmenu_flag = 0; // IR Menu Button Active flag//bit irinpsel_flag = 0; // IR Inp_sel Button Active flagbit irexit_flag = 0; // IR Exit Button Active flagbit irup_flag= 0; // IR Menu+ Button Active flagbit irdown_flag= 0; // IR Menu- Button Active flagbit irright_flag = 0; // IR Right Button Active flagbit irleft_flag = 0; // IR Left Button Active flagbit irsource_flag=0;bit irbriadd_flag=0;bit irbrisub_flag=0;bit irvoladd_flag=0;bit irvolsub_flag=0;bit irtimer_flag=0;//extern void aisel_func(char aisel);//***************************************************************extern bit power_flag ; // defined in the globl.h extern unsigned int idata osd_timer;bit ir_ok_flag=0;//**********************************************************************typedef struct { unsigned int customer; unsigned char ir_code; unsigned char _code;}IR_CODE_TYPE ;static IR_CODE_TYPE IR_CODE={0,0,0};static bit ir_start_flag=0;// bit last_code_com=0; // A flag to show whether the last IR code receive is complete unsigned long IR_data=0;//*********************************************************************************//extern void DelayXms(char);unsigned char GetCycle(void);void Delay50us();extern char data channel;//----------------------------------------------------static char ispcomd[8]="prog....";static char usercode[8]="WB05D000";//----------------------------------------------------static char data _test;extern bit XIE_Power;//*******************************************************************void ir_server(){ if(ir_ok_flag==1){ ir_ok_flag=0; EA=0; #if _debug printf("\n"); printf("customer=%x",IR_CODE.customer); printf(" code=%bx",IR_CODE.ir_code); printf(" ^code=%bx\n",IR_CODE._code); #endif TI=0; if(IR_CODE.customer==ir_customer){ switch(IR_CODE.ir_code){ //============= TEST IR ========================== case irkey_0: #if _debug printf("the key is 0.\n"); #endif osd_timer=0;TR0=1; break; case irkey_1: #if _debug printf("the key is 1.\n"); #endif osd_timer=0;TR0=1; break; case irkey_2: #if _debug printf("the key is 2.\n"); #endif osd_timer=0;TR0=1; break; case irkey_3: #if _debug printf("the key is 3.\n"); #endif osd_timer=0;TR0=1; break; case irkey_4: #if _debug printf("the key is 4.\n"); #endif osd_timer=0;TR0=1; break; case irkey_9: //broning. #if _debug printf("the key is 9.\n"); #endif osd_timer=0;TR0=1; break; case irtest: #if _debug printf("test\n"); #endif irtimer_flag=1; break; //=========== ISP BUTTON ========== case irkey_isp: //broning. #if _debug printf("the key is 9.\n"); #endif CHPENR=0x87; CHPENR=0x59; CHPCON=0x03; CHPENR=0x00; IP=0x02; EA=1; ET0= 1; TH0=0x04; TL0=0x04; TMOD=0x02; TR0=1; PCON=1; break; //============================================== case irkey_power: // Power Button osd_timer=0;TR0=1; #if _debug printf("the key is power.\n"); #endif irpower_flag = 1; // IR Power Button Active XIE_Power=0; osd_timer=0;TR0=1; break; case irkey_mute: #if _debug printf("the key is mute.\n"); #endif osd_timer=0; if(power_flag) { mute_flag=~mute_flag; if(mute_flag){ //mute_disp();printf("mute_menu run\n"); set_audio_mute(1); #if _debug printf("set_audio_mute.\n"); #endif } else{ osd_show(0x28, 1, &NULLC) ; load_audio_volume(); #if _debug printf("load_audio_volume.\n"); #endif } } osd_timer=0;TR0=1; break; case irkey_source: // Inp_sel Button osd_timer=0;TR0=1; if (power_flag){ irsource_flag= 1; // IR Inp_sel Button Active } osd_timer=0;TR0=1; break; case irkey_menu: // Menu Button osd_timer=0;TR0=1; #if _debug printf("the key is menu.\n"); #endif if (power_flag){ irmenu_flag = 1; // IR Menu Button Active } osd_timer=0;TR0=1; break; //---------------up down left right ------------------- case irkey_up: // Menu+ Button osd_timer=0;TR0=1; #if _debug printf("the key is up.\n"); #endif if (power_flag){ irup_flag = 1; // IR Menu+ Button Active } osd_timer=0;TR0=1; break; case irkey_down: // Menu- Button osd_timer=0;TR0=1; #if _debug printf("the key is down.\n"); #endif if (power_flag){ irdown_flag = 1; // IR Menu- Button Active } osd_timer=0;TR0=1; break; case irkey_right: // Right Button osd_timer=0;TR0=1; #if _debug printf("the key is right.\n"); #endif if (power_flag) { irright_flag = 1; // IR Right Button Active } osd_timer=0;TR0=1; break; case irkey_left: // Left Button osd_timer=0;TR0=1; #if _debug printf("the key is left.\n"); #endif if (power_flag) { irleft_flag = 1; // IR Left Button Active } osd_timer=0;TR0=1; break; //----brightness + - and volume + - ----------------- case irkey_bri_add: osd_timer=0;TR0=1; if(power_flag){ topmenu_flag=0; irbriadd_flag=1; } osd_timer=0;TR0=1; #if _debug printf("the key is bri_add.\n"); #endif break; case irkey_bri_sub: osd_timer=0;TR0=1; if(power_flag){ topmenu_flag=0; irbrisub_flag=1; } osd_timer=0;TR0=1; #if _debug printf("the key is bri_sub.\n"); #endif break; case irkey_vol_add: osd_timer=0;TR0=1; if(power_flag){ topmenu_flag=0; irvoladd_flag=1; } osd_timer=0;TR0=1; #if _debug printf("the key is vol_add.\n"); #endif break; case irkey_vol_sub: if(power_flag){ topmenu_flag=0; irvolsub_flag=1; } osd_timer=0;TR0=1; break; #if _debug printf("the key is vol_sub.\n"); #endif //----------------------------------------------- default: #if _debug printf("ther key wasn't defined .\n"); #endif break; } IR_data=0; } else{ printf("the IR_customer is error.\n"); } ir_start_flag=0; } else{ EX1=1; EA=1; } }//**************************************************************************void ir_int1(void) interrupt 2 using 1{ unsigned char i; unsigned char data Count; EX1 = 0; IR_data=0; Count=GetCycle(); if((Count>175) &&(Count<215)){ ir_start_flag=1; } // The first press button //else if((Count>145)&&(Count<165)){ /*ir_rep_flag=1;*/ // ir_start_flag=1;//printf("count=%bx\n",Count); //}//repeat press some button . else{ EX1 = 1; return ; } //not all //----------------------------------------------------------- if(ir_start_flag){ //begin to receive the ir_code . for(i=32;i>0;i--){ Count=GetCycle(); IR_data <<= 1; if((Count>26) && (Count<38)) IR_data ++; else if((Count>10) && (Count<0x21)) ; else { EX1=1; return; } } } IR_CODE._code=(char)IR_data; IR_data>>=8; IR_CODE.ir_code=(char)IR_data; IR_data>>=8; IR_CODE.customer=(int)IR_data; ir_ok_flag=1;}//***********************************************************************unsigned char GetCycle(void){ unsigned char data a=0; while(!IR) { Delay50us(); a++; if(a>220){ return a; } } while(IR) { Delay50us(); a++; if(a>220){ return a; } } return(a);}//********************************************************************void Delay50us(void){ unsigned char data a; for(a=10;a>0;a--){ _nop_(); _nop_(); _nop_(); _nop_(); _nop_(); }}//************************************************************************* //**********************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -