📄 ir_nec.lst
字号:
C51 COMPILER V8.18 IR_NEC 09/29/2009 23:44:50 PAGE 1
C51 COMPILER V8.18, COMPILATION OF MODULE IR_NEC
OBJECT MODULE PLACED IN ..\..\1out\Ir_nec.obj
COMPILER INVOKED BY: d:\Keil\C51\BIN\C51.EXE ..\..\msFunc\Ir_nec.c OPTIMIZE(SIZE) BROWSE INCDIR(..\..\inc;..\..\mslib;..
-\..\Device;..\..\kernal;..\..\msFunc;..\..\pc;..\..\tv) DEFINE(Multi_language) DEBUG OBJECTEXTEND PRINT(..\..\1out\Ir_ne
-c.lst) OBJECT(..\..\1out\Ir_nec.obj)
line level source
1 /******************************************************************************
2 Copyright (c) 2004 MStar Semiconductor, Inc.
3 All rights reserved.
4
5 [Module Name]: Ir.c
6 [Date]: 04-Feb-2004
7 [Comment]:
8 Remote control subroutines.
9 [Reversion History]:
10 *******************************************************************************/
11 #ifdef IR_NEC
#define _IR_C_
// System
#include <intrins.h>
// Common
#include "types.h"
#include "global.h"
// Internal
#include "ir.h"
#include "debug.h"
//XDATA WORD ir_data,ir_data_bk;
//XDATA BYTE ir_data_ref;
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
void irDecodeRepaeat(WORD wRepeatTime)
{
if ( g_bIrRepeat ) // repeat command
{
g_bIrRepeat = 0;
g_bIrTime = 1; // start TIMER0 to repeat IR command
g_wIrTimer = wRepeatTime; // reset repeat timer
}
else // first command before repeat
{
g_bIrTime = 1; // start TIMER0 to repeat IR command
g_wIrTimer = IR_REPEAT_START_TIME; // set timer to check repeat
}
}
////////////////////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////////////////////
void irDecodeEnd( void )
{
g_bIrCommand = 0; // end IR command
// clear repeat flag
g_bIrCheckRepeat = 0;
g_bIrRepeat = 0;
g_wIrTimer = IR_DELAY_TIME; // any value
C51 COMPILER V8.18 IR_NEC 09/29/2009 23:44:50 PAGE 2
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
#if ENABLE_MCU_USE_INTERNAL_CLOCK
void irInterruptProcess_NewClk(void)
{
// --------------------------------------------------------------
#if (IR_TIMER_SEL == IR_USE_TIMER1)
TR1 = 0; // stop timer1
g_wIrPeriodCnt = MAKEWORD(TH1, TL1);
TH1 = HIBYTE(IR_TIMER_COUNTER_NEW);
TL1 = LOBYTE(IR_TIMER_COUNTER_NEW);
TMOD = (TMOD & 0x0f) | 0x10; // timer1 mode to counter
g_bUartDisable = 1;
TF1 = 0; // clear timer1 overflow flag
ET1 = 1; // enable timer1 interrupt
TR1 = 1; // start timer1
#endif
#if (IR_TIMER_SEL == IR_USE_TIMER2)
TR2 = 0; // stop timer2
g_wIrPeriodCnt = MAKEWORD(TH2, TL2);
TH2 = HIBYTE(IR_TIMER_COUNTER_NEW);
TL2 = LOBYTE(IR_TIMER_COUNTER_NEW);
TF2 = 0; // clear timer2 overflow flag
ET2 = 1; // enable timer2 interrupt
TR2 = 1; // start timer2
#endif
// --------------------------------------------------------------
if (g_bIrExecute == 0) // 1st tigger
{
g_bIrExecute = 1;
g_ucIrBitsCnt = 0;
g_wIrCycleTimer = IR_CYCLE_TIME;
return;
}
// --------------------------------------------------------------
g_wIrPeriodCnt -= IR_TIMER_COUNTER_NEW; // difference of triggers
if (g_ucIrBitsCnt == 0) // check lead header
{
// check genral lead code
if (g_wIrPeriodCnt > irGetMinCnt_NEW(IR_1ST_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt_NEW(IR_1ST_
-LEAD_TIME))
{
g_bIrError = 0;
g_bIrRepeat = 0;
#ifdef IR_DEBUG_EN
g_ucAddresCode0 = 0x00;
g_ucAddresCode1 = 0x00;
#endif
g_ucDataCode = 0x00;
g_ucIrDataFifo = 0x00;
}
// check repeat lead code
C51 COMPILER V8.18 IR_NEC 09/29/2009 23:44:50 PAGE 3
else if (g_bIrRepeatStatus)
{
// check repeat lead code
if (g_wIrPeriodCnt > irGetMinCnt_NEW(IR_REPAEAT_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt_NEW
-(IR_REPAEAT_LEAD_TIME))
{
if (g_bIrCheckRepeat)
{
g_bIrRepeat = 1;
g_bIrDetect = 1;
g_wIrTimer = IR_DELAY_TIME;
}
#ifdef IR_DEBUG_EN
#if (IR_TIMER_SEL == IR_USE_TIMER1)
TF1 = 1;
#endif
#if (IR_TIMER_SEL == IR_USE_TIMER2)
TF2 = 1;
#endif
#endif
}
g_wIrCycleTimer = IR_CYCLE_TIME;
g_bIrExecute = 0;
return;
}
else // fail lead code
{
g_bIrExecute = 0;
return;
}
}
// --------------------------------------------------------------
else // receive byte code
{
// receive bit
g_ucIrDataFifo >>= 1;
if (g_wIrPeriodCnt > irGetMinCnt_NEW(IR_LOGIC0_TIME) && g_wIrPeriodCnt < irGetMaxCnt_NEW(IR_LOGIC0
-_TIME))
; // logic 0
else if (g_wIrPeriodCnt > irGetMinCnt_NEW(IR_LOGIC1_TIME) && g_wIrPeriodCnt < irGetMaxCnt_NEW(IR_
-LOGIC1_TIME))
g_ucIrDataFifo |= _BIT7; // logic 1
else // mismatch
g_bIrError = 1;
// check bits counter
switch(g_ucIrBitsCnt)
{
case 8: // 1st byte
#ifdef IR_DEBUG_EN
g_ucAddresCode0 = g_ucIrDataFifo;
#endif
if (g_ucIrDataFifo == IR_HEADER_CODE0||g_ucIrDataFifo == 0x00) // for HouDa rmc
;
else
g_bIrError = 1;
break;
case 16: // 2nd byte
#ifdef IR_DEBUG_EN
g_ucAddresCode1 = g_ucIrDataFifo;
#endif
if (g_ucIrDataFifo == IR_HEADER_CODE1||g_ucIrDataFifo == 0x00) // for HouDa rmc
C51 COMPILER V8.18 IR_NEC 09/29/2009 23:44:50 PAGE 4
;
//if (g_ucIrDataFifo != IR_HEADER_CODE1)
else
g_bIrError = 1;
break;
case 24: // 3rd byte
g_ucDataCode = g_ucIrDataFifo;
break;
case 32: // 4th byte
if (g_ucDataCode != ~g_ucIrDataFifo)
g_bIrError = 1;
if (!g_bIrError)
{
g_bIrRepeatStatus = 1;
g_ucIrCode = g_ucDataCode;
g_wIrCycleTimer = IR_CYCLE_TIME;
g_bIrDetect = 1;
g_bIrCommand = 1;
g_bIrTime = 0; // IR 1st time repeat
g_bIrCheckRepeat = 0;
g_wIrTimer = IR_DELAY_TIME;
}
g_bIrExecute = 0;
#ifdef IR_DEBUG_EN
#if (IR_TIMER_SEL == IR_USE_TIMER1)
TF1 = 1;
#endif
#if (IR_TIMER_SEL == IR_USE_TIMER2)
TF2 = 1;
#endif
#endif
return;
} // switch
} // if (g_ucIrBitsCnt == 0)
g_ucIrBitsCnt++; // next bit
}
#endif
void irInterruptProcess(void)
{
// --------------------------------------------------------------
#if (IR_TIMER_SEL == IR_USE_TIMER1)
TR1 = 0; // stop timer1
g_wIrPeriodCnt = MAKEWORD(TH1, TL1);
TH1 = HIBYTE(IR_TIMER_COUNTER);
TL1 = LOBYTE(IR_TIMER_COUNTER);
TMOD = (TMOD & 0x0f) | 0x10; // timer1 mode to counter
g_bUartDisable = 1;
TF1 = 0; // clear timer1 overflow flag
ET1 = 1; // enable timer1 interrupt
TR1 = 1; // start timer1
#endif
#if (IR_TIMER_SEL == IR_USE_TIMER2)
TR2 = 0; // stop timer2
g_wIrPeriodCnt = MAKEWORD(TH2, TL2);
TH2 = HIBYTE(IR_TIMER_COUNTER);
TL2 = LOBYTE(IR_TIMER_COUNTER);
C51 COMPILER V8.18 IR_NEC 09/29/2009 23:44:50 PAGE 5
TF2 = 0; // clear timer2 overflow flag
ET2 = 1; // enable timer2 interrupt
TR2 = 1; // start timer2
#endif
// --------------------------------------------------------------
if (g_bIrExecute == 0) // 1st tigger
{
g_bIrExecute = 1;
g_ucIrBitsCnt = 0;
g_wIrCycleTimer = IR_CYCLE_TIME;
return;
}
// --------------------------------------------------------------
g_wIrPeriodCnt -= IR_TIMER_COUNTER; // difference of triggers
if (g_ucIrBitsCnt == 0) // check lead header
{
// check genral lead code
if (g_wIrPeriodCnt > irGetMinCnt(IR_1ST_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt(IR_1ST_LEAD_TIM
-E))
{
g_bIrError = 0;
g_bIrRepeat = 0;
#ifdef IR_DEBUG_EN
g_ucAddresCode0 = 0x00;
g_ucAddresCode1 = 0x00;
#endif
g_ucDataCode = 0x00;
g_ucIrDataFifo = 0x00;
}
// check repeat lead code
else if (g_bIrRepeatStatus)
{
// check repeat lead code
if (g_wIrPeriodCnt > irGetMinCnt(IR_REPAEAT_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt(IR_REPA
-EAT_LEAD_TIME))
{
if (g_bIrCheckRepeat)
{
g_bIrRepeat = 1;
g_bIrDetect = 1;
g_wIrTimer = IR_DELAY_TIME;
}
#ifdef IR_DEBUG_EN
#if (IR_TIMER_SEL == IR_USE_TIMER1)
TF1 = 1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -