📄 myremotereception.c
字号:
#pragma SFR //special function register
#pragma NOP
#pragma DI
#pragma EI
//interrupt serve function name inter_P0.
#pragma INTERRUPT INTP0 Inter_P0
//interrupt serve function name Inter_TM1.
#pragma interrupt INTTM01 Inter_TM1
/*
**PROJECT = HDTV REMOTE CONTROL RECEPTION PROCESSING
**MODULE = MyRemoteReceptionModi.c
**SHORT DESC. = Remote control reception && key value processing
**DEVICE = UPD789417
**VERSION = 0.1
**DATE = 03.07.2003
**LAST CHANGE = -
*/
#include "MyDefine.h"
#include "MyRemoteReception.h"
//the bit for remote control infrared ray reception
#define g_btIR P2.4
//g_TempRMDATA:(Valid data storage area)the ReMote input DATA is saved.
sreg Uchar g_TempRMDATA;
//The prefix "s_g_" indicates Static Outer variables.
//s_g_RPTCT -- RePeaT code valid time CounTer
static sreg Uchar s_g_RPTCT;
//s_g_RMENDCT -- input time CounTer for ReMote data input end
static sreg Uchar s_g_RMENDCT;
static sreg Uchar s_g_SELMODE; //s_g_SELMODE -- SELection MODE
//s_g_LD_CT -- Leader signal Detection CounTer
static sreg Uchar s_g_LD_CT = 5;
//static sreg Uchar TM1CntValue; //TM1CntValue -- TM1 Count Value
/*s_tempCodes[0] -- custom code; s_tempCodes[1] -- custom code inverted;
s_tempCodes[2] -- data code; s_tempCodes[3] -- data code inverted
*/
//static sreg Uchar s_tempCodes[4];
//s_tempByte -- assigned temporarily to code by byte
//static sreg Uchar s_tempByte;
//s_byteCntAccepted -- byte counts that have been accepted
//static sreg Uchar s_byteCntAccepted;
//s_bitCntAccepted -- bit counts that have been accepted
//static sreg Uchar s_bitCntAccepted;
bit g_btRPT; //g_btRPT -- RePeaT(flag for repeat valid time)
bit g_btRMDTSET; //g_btRMDTSET -- ReMote DaTa SET
//g_btIPDTFG -- Decision FlaG indicating the presence of a valid InPut
// DaTa signal
bit g_btIPDTFG;
//bit btkeyPress; //present the status of any keys
bit btKeyPressedTooLong;
static bit s_g_btRMDTOK;//Presence of a valid input ReMote DaTa signal
Uchar g_keyFlgCnt = 0; //2003-9-24 14:51
void S_LOWCT();
void S_M0SET();
void Delay100usIR();
void LEAD_H();
void LEAD_L();
void CDCODE();
void REPCD();
void ENDCHK();
Uchar CR_READ();
void S_M5SET();
/*
** Function name: InitReceive
**
** Description:
** The function initializes the variables used firstly.
**
** Note: sreg variables is automatically set to 0 by system, so we are
** allowed not to initialize the variables manually.
** But I should adopt the good routine. If ROM is not enough,
** then consider deleting the step of initialization.
**
** Input parameters:
** no
**
** Output parameters:
** no
**
** Return value:
** no
*/
void InitReceive()
{
//g_TempRMDATA -- (Valid data storage area)the ReMote input DATA
// is saved.
g_TempRMDATA = 0;
s_g_RPTCT = 0; //s_g_RPTCT -- RePeaT code valid time CounTer
s_g_RMENDCT = 0;
s_g_btRMDTOK = 0;
s_g_SELMODE = 0;
g_btRPT = 0; //g_btRPT -- RePeaT(flag for repeat valid time)
g_btRMDTSET = 0; //g_btRMDTSET -- ReMote DaTa SET
//g_btIPDTFG -- Decision FlaG indicating the presence of a valid
// InPut DaTa signal
g_btIPDTFG = 0;
}
/*
**====================================================================
** leader code:9mS(L) 4.5mS(H) <NEC FORMATE -- L:low;H:high>
** __ _____ _ __ ___________________________
** \________/ \_/ \_/ \_..\_/
**
**====================================================================
*/
/*
** Function name: Inter_TM1
**
** Description:
** The function is ISR - Interrupt Service Routine of timer1
** interval timer and used for remote control signal timer
** processing.
**
** Input parameters:
** no
**
** Output parameters:
** no
**
** Return value:
** no
*/
void Inter_TM1()
{
EI(); //Enable multiplexed interrupt.
if(g_btIPDTFG) //Is the InPut DaTa signal present?
{
if(s_g_btRMDTOK) //Is ReMote DaTa valid?
{
S_LOWCT(); //Leader code detection
s_g_RPTCT--; //RePeaT code valid time CounTer is decreased by 1.
if(0 == s_g_RPTCT) //RePeaT code invalid time is up.
{
g_btRPT = 0; //RePeaT code becomes invalid state after 250ms.
g_btIPDTFG = 0;
s_g_btRMDTOK = 0;
//****the following????????
btKeyPressedTooLong = 1; //Show key is pressed too long.
//03-7-16 11:25 在这里加入一按键结束标志置1!!!!!!
//对于btkeyPress为零之前,可能已经度过n个108ms在加上250ms-40.5ms+3*1.5ms
//btkeyPress = 0;
//TCE02 = 0; //stop timing when the key is lifted.
/*
if((TM02Cnt > 33)&&(TM02Cnt < 217)&&(key800msCnt = 1))
{
TM02Cnt = 0;
key800msCnt = 0;
btShortTime = 1;
}
if(key800msCnt > 1)
{
btShortTime = 0;
btLongTime = 1;
}
*/
//在此处启动一定时器3计时按键的时间间隔,如果本次按键结束到下次按键发码的
//时间间隔大于某个tx(800ms)则认为前次按键被确认。如果按同一个键的话,则不
//响应。不管如何,如果按不同的键的话在后一个位置显示。
} //The end of if(0 == s_g_RPTCT)
} //The end of if(s_g_btRMDTOK)
else
{
s_g_RMENDCT--; //CounTer for ReMote data input end is decreased
// by 1. And the former value is 3.
if(0 == s_g_RMENDCT)
{
s_g_btRMDTOK = 1; //Set to valid data is present.
g_btRMDTSET = 1; //Indicate any key is well pressed.
btKeyPressedTooLong = 0; //???2003-9-24 10:23
//2003-9-23 16:27
//btkeyPress = 1;
//2003-9-24 10:27
++g_keyFlgCnt; //???
if(g_keyFlgCnt >= 2)
{
g_keyFlgCnt = 0; //2003-10-31 16:41
}
//2003-9-23 16:27
TCE02 = 1; //Start timer2 when the key is valid.
S_M0SET(); //Set registers before Selecting Mode0 - leader(low)
//detection mode.
} //The end of if(0 == s_g_RMENDCT)
s_g_LD_CT = 5; //Leader signal Detection CounTer is assigned to 5.
} //The end of else of if(s_g_btRMDTOK)
} //The end of if(g_btIPDTFG)
else
{
S_LOWCT();
} //the end of else of if(g_btIPDTFG)
}
/*
** Function name: S_LOWCT
**
** Description:
** The function is to detect low-level input every 1.5 ms. The
** low-level pulse width of the leader code cannot be measured
** until low-level remains in five consecutive times.
**
** Input parameters:
** no
**
** Output parameters:
** no
**
** Return value:
** no
*/
void S_LOWCT()
{
if(0 == s_g_SELMODE)
{
if(!g_btIR)
{
s_g_LD_CT--; //Leader signal Detection CounTer is decreased by 1.
if(0 == s_g_LD_CT)
{
s_g_SELMODE = 1; //Leader(low) measurement mode
TMC01 = 0x02; //Operation disabled(TM1 is cleared to 0.)
CR01 = 0x97;
TMC01 = 0x82; //8bitTimer1 is set to 7.81ms and start.
PMK0 = 1;
INTM0 = 0xa4; //INTP0 is rising edge interrupt 03-6-24 16:37
PIF0 = 0;
PMK0 = 0; //Enable INTP0
s_g_LD_CT = 5; //Leader signal Detection CounTer is assigned to 5.
}
} //The end of if(!g_btIR)
else
{
s_g_LD_CT = 5; //Leader signal Detection CounTer is assigned to 5.
}
} //The end of if(0 == s_g_SELMODE)
else
{
S_M0SET(); //Set registers before Selecting Mode0 - leader(low)
//detection mode.
s_g_LD_CT = 5; //Leader signal Detection CounTer is assigned to 5.
} //The end of else of if(0 == s_g_SELMODE)
}
/*
** Function name: Inter_P0
**
** Description:
** The function is ISR - Interrupt Service Routine of external
** interrupt INTP0 and used for remote control signal edge
** detection processing.
**
** Input parameters:
** no
**
** Output parameters:
** no
**
** Return value:
** no
*/
void Inter_P0()
{
Delay100usIR(); //100us wait
switch(s_g_SELMODE)
{
case 1:
LEAD_L(); //LEADer Low detection processing 03-6-24 16:38
break;
case 2:
LEAD_H(); //LEADer High detection processing 03-6-24 16:38
break;
case 3:
CDCODE(); //Custom/Data CODE read processing
break;
case 4:
REPCD(); //REPeat CoDe detection processing
break;
case 5:
ENDCHK(); //Error data detection processing
break;
default:
break;
}
}
/*
** Function name: LEAD_L
**
** Description:
** The function is to process leader low detection.
**
** Input parameters:
** no
**
** Output parameters:
** no
**
** Return value:
** no
*/
void LEAD_L()
{
Uchar TM1Cnt;
if(g_btIR) //level check g_btIR = 0:noise 03-6-24 16:42
{
Delay100usIR(); //100us wait
if(g_btIR)
{
TM1Cnt = CR_READ();
if(TM1Cnt >= 0x0e) //Timer value read: 6.8ms - (1.5ms * 4)
{
if(TM1Cnt <= 0x52) //11.8ms - (1.5ms * 5)
{
s_g_SELMODE = 2;
INTM0 = 0xa0; //INTP0 is falling edge interrupt
}
else
{
S_M0SET();
}
}
else
{
S_M0SET();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -