?? ir_receiver.c
字號:
//#include <at89x52.H> // SFR definition header file
#include <reg54.h>
#include <stdio.h> // prototype declarations for I/O functions
#include "SystemEvent.h"
//#include "enum.h"
//#include "StructDef.h"
#include "Function.h"
#include "ExtVar.h"
#include <rtx51tny.h> /* RTX-51 tiny functions & defines */
#include "RTOS.h"
#include "IRKey.h"
void InitTimer2(void){
TH2 =0x00;// (unsigned char) PERIOD; // set timer period
TL2 = 0x00;//(unsigned char) PERIOD;
RCAP2H = 0xe8;
RCAP2L = 0x00;
CP_RL2=0;
C_T2=0;
TR2=1; // auto reload mode
}
void ResetRemoteCTRL_Use_Timer1(void);
void InitRemoteCTRL(void){
_RC_Data=0;
_RC_CTRL_Active=0;
ResetRemoteCTRL_Use_Timer1();
_IR_RepeatKeyDelay=_ClockX+0x80;
// InitTimer2();
}
#define SMOD_ 0x80
sbit _IRx=P3^5;
void ResetRemoteCTRL_Use_Timer1(void){
// Timer1 initial to counter mode
// It interrupt T1_INT every once a falling edge input from T1 pin tigger from remote controller
_IRx=1;
_xbit=_IRx;
// Set counter T1 mod =1;
PCON|=SMOD_;
TH1 =0xff;
TL1 = 0xff;
TMOD&=0x0f;
TMOD = TMOD | 0x60; // select mode 2
TCON&=0xf0;
// TCON|=0x05;
// enable timer 0 interrupt
TR1=1;
_RC_Word=0xffffffff;
_RC_CTRL_Reset=1;
_RC_RepeatCommand=1;
IP=0x08; // Timer1 hightest piroty
ET1 = 1;
EA = 1;
}
void timer1 (void) interrupt 3 using 1 {
P2^=0x08;
/*
unsigned char _gx;
unsigned char _HiByte,_LowByte;
_gx=TH2;
TH2=0x00;
TL2=0x00;
// if(_Busy==1) return;
_IRTimeOut=_ClockX+5;
// _KeyTempX=0x09;//DetectButtomKey(); // pull which key press
// isr_send_signal(_HDMIFuncX);
if(_RC_CTRL_Reset){
_RC_CTRL_Reset=0;
_RC_RepeatCommand=0;
_CountOf_RC_Pulse=0x00; // because we expect next pulse been detect will be a start bit
TR1=0;
_FuncX|=_IRCommand;
isr_send_signal(_Init); // and must be skip so initial the pulse counter to 0xff
}
else {
if(_CountOf_RC_Pulse==0x00){
if(_gx==0x28){ _RC_CTRL_Reset=1;
if(_IR_RepeatKeyEnable){
_RC_RepeatCommand=1;
//_AL260FunctionModex
_FuncX|=_IRCommand;
isr_send_signal(_Init);//_AL260FuncX);
}
}
else if(_gx==0x30) _CountOf_RC_Pulse=0x20;
else _CountOf_RC_Pulse=0;
}
else {
// Since our timer_0 interval set to 0x3800 / (11059200/12) = 15.5 ms so TH0/TL0 = 0x10000-0x3800 = 0xc800; count up
// and the time slot between reset pulse to start bit pulse been measure is 13.68 ms
// time slot of "0" is 1.12 ms = 4.02 scale of TH0 counter
// time slot of "1" is 2.24 ms = 8.04 scale of TH0 counter
// so we select a threshold value 5 to test "0" or "1" input
_RC_Word<<=1;
if(_gx>5) _RC_Word|=0x00000001;
--_CountOf_RC_Pulse;
if(!_CountOf_RC_Pulse){ _RC_CTRL_Reset=1;
_HiByte=(unsigned char)((_RC_Word>>8)&0x00ff);
_LowByte=(unsigned char)(_RC_Word &0x00ff);
// _RC_x=_RC_Word;
if((_LowByte+_HiByte)==0xff){
// _IRTimeOut=_ClockX+10;
_FuncX|=_IRCommand;
isr_send_signal(_Init);//_AL260FuncX);
_IR_RepeatKeyDelay=_ClockX+0x8;
_IR_RepeatKeyEnable=0;
}
}
else if(_gx>0x0a) _RC_CTRL_Reset=1;
}
}
*/
}
/**/
code unsigned char _RCKeyTable[0x1e]={
_1x,// 0x08 // 08f7 61d6
_2x,// 0x88 // 8877 61d6
_3x,// 0x48 // 48b7 61d6
_4x,// 0xc8 // c837 61d6
_5x,// 0x28 // 28d7 61d6
_6x,// 0xa8 // a857 61d6
_7x,// 0x68 // 6897 61d6
_8x,// 0xe8 // 8e17 61d6
_9x,// 0x18 // 18e7 61d6
_0x,// 0x58 // 58a7 61d6
_Recall,// 0xd8 // d827 61d6
_Scan,// 0x98 // 9867 61d6
_Select,// 0x50 // 50af 61d6
_Up,// 0x10 // 10ef 61d6
_Left,// 0x90 // 906f 61d6
_Right,// 0xd0 // d02f 61d6
_Down,// 0x30 // 30cf 61d6
_Menu,// 0xf0 // f00f 61d6
_ExitRC,// 0x70 // 708f 61d6
_Res,// 0xb0 // b04f 61d6
_Input,// 0xa0 // a05f 61d6
_Mts,// 0x60 // 609f 61d6
_Mute,// 0xe0 // e01f 61d6
_Channel_Add,// 0x40 // 40bf 61d6
_Channel_Sub,// 0x80 // 807f 61d6
_Volume_Add,// 0xc0 // c03f 61d6
_Volume_Sub,// 0x20 // 20df 61d6
_Power,// 0x00 // 00ff 61d6
_Repeat,// 0xa5 // 00ff 61d6
_UnKnow // 0xff
};
unsigned char DecodeIRCommand(unsigned long _RC_WordX){
unsigned char _RC_DataX;
unsigned char _gx;
unsigned char _hx;
unsigned char _ix;
unsigned int _Xadr;
_Xadr=(unsigned int)((_RC_WordX>>0x10)&0x0000ffff);
if(_Xadr==0x61d6){
// 0x61d6 is a ID code transmitted from remote controller
// _RC_Word>>=0x10;
_Xadr=(unsigned int)(_RC_WordX&0x0000ffff);
_gx=(unsigned char)(_Xadr&0x00ff);
_Xadr>>=8;
_hx=(unsigned char)(_Xadr&0x00ff);
if((_hx|_gx)==0xff){
for(_ix=0;_ix<0x1d;_ix++){
if(_hx==_RCKeyTable[_ix]) break;
}
if(_ix<0x1d){
_RC_DataX=_hx;
// RunRCFuncX(_RC_Data);
}
else _RC_DataX=0xff; // unknow
}
}
else {
if((_RC_RepeatCommand==1)&&(_RC_Data!=0xff)){
_RC_DataX=0xf0;
}
}
return(_RC_DataX);
}
unsigned char RCFuncX(unsigned char _RC_DataX){
static unsigned char _gx;
unsigned char _dx;
switch(_RC_DataX){
case _Right:
case _Up:
case _1x:
_gx=_AddKey;
_dx=_gx;
break;
case _Down:
case _Left:
case _2x:
_gx=_SubKey;
_dx=_gx;
break;
case _Select:
case _3x:
_gx=_SelKey;
_dx=_gx;
break;
case _4x:
break;
case _5x:
case _6x:
case _7x:
case _8x:
case _9x:
case _0x:
case _Recall:
case _Scan:
// case _Select:
// case _Up:
// case _Left:
// case _Right:
// case _Down:
case _Menu:
break;
case _ExitRC:
// if(_DebugMode==0){_DebugMode=1; ResetRemoteCTRL_Use_Timer1(); }
// else _DebugMode=0;
break;
case _Res:
// ResetRemoteCTRL_Use_Timer1();
break;
case _Repeat:
_dx=_gx;
break;
case _Input:
case _Mts:
case _Mute:
case _Channel_Add:
case _Channel_Sub:
case _Volume_Add:
case _Volume_Sub:
case _Power:
case _UnKnow:
break;
}
return(_dx);
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -