📄 ir_nec.c
字号:
#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(IR_LOGIC0_TIME) && g_wIrPeriodCnt < irGetMaxCnt(IR_LOGIC0_TIME))
; // logic 0
else if (g_wIrPeriodCnt > irGetMinCnt(IR_LOGIC1_TIME) && g_wIrPeriodCnt < irGetMaxCnt(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
;
//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;
default:
break;
} // switch
} // if (g_ucIrBitsCnt == 0)
g_ucIrBitsCnt++; // next bit
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void irDetectTimer0( void )
{
if (g_wIrCycleTimer)
g_wIrCycleTimer--;
else
{
g_bIrExecute = 0;
g_bIrRepeatStatus = 0;
}
//--- check IR repeat command delay time ---
if ( g_bIrCommand ) // check IR command start
{
g_wIrTimer--;
if ( g_wIrTimer == 0 ) // time out
{
if ( g_bIrTime ) // for 1st IR command
{
// IR 1st command executed then delay
g_bIrTime = 0; // clear 1st IR command status
g_wIrTimer = IR_REPEAT_END_TIME;
g_bIrCheckRepeat = 1; // ready to repeat
}
else // IR repeat end or IR decode too late
{
// IR repeat command delay timer
g_bIrCommand = 0;
g_ucIrCode = 0xff;
g_bIrCheckRepeat = 0;
}
} // if time out
} // if IR command
/*
//--- IR press 0-9 key ending timer for TUNER Channel---
if ( g_bIrNumKeyStart || g_bIr100Key ) // IR key start
{
g_wIrNumKeyTimer--;
if ( g_wIrNumKeyTimer == 0 ) // time out
{
if ( _testbit_( g_bIr100Key ) )
g_ucIrNumKey = ( g_ucIrNumKey * 10 ) + 100;
g_bIrNumKeyStart = 0;
g_bIrKeyNumEnd = 1;
g_wIrNumKeyTimer = 200;
}
}
else
g_bIrKeyNumEnd = 0;
*/
// if IR key start
// if (g_bIrKeyNumEnd && g_wIrNumKeyTimer)
// if ((--g_wIrNumKeyTimer) == 0)
// g_bIrKeyNumEndDelay = 1;
}
//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
void irDetectTimer1( void )
{
#if (IR_TIMER_SEL == IR_USE_TIMER1)
ET1 = 0; // disable timer1 interrupt
TR1 = 0; // stop timer1
if (!g_wIrCycleTimer || g_bIrRepeatStatus)
g_bIrExecute = 0;
// setting for uart
g_bUartDisable = 0;
TMOD = (TMOD & 0x0f) | 0x20; // timer1, mode 2, 8-bit reload
TH1 = TIMER1_MODE2_TH1; // set timer1(buad rate)
TR1 = 1; // start timer1
#endif
#if (IR_TIMER_SEL == IR_USE_TIMER2)
ET2 = 0; // disable timer2 interrupt
TR2 = 0; // stop timer2
if (!g_wIrCycleTimer || g_bIrRepeatStatus)
g_bIrExecute = 0;
TR2 = 1; // start time12
#endif
}
#ifdef IR_DEBUG_EN
void DebugIRHandler(void)
{
if (g_bIrDetect)
{
if (g_bIrRepeat)
printMsg('R');
else
{
printf("\r\ng_ucAddresCode0=%x",g_ucAddresCode0);
printf("\r\ng_ucAddresCode1=%x",g_ucAddresCode1);
printf("\r\ng_ucDataCode=%x",g_ucDataCode);
}
}
}
#endif
#if IRSEND_ENABLE
void IRSendInital(BYTE ComData)
{
hw_ClrIRsend_Pin();
g_bIRSendEnable=1;
g_ucIRSendCount=13;// Head 13.5ms
g_ucIRSendStatus=0;
g_ucIRSendSYSData1=0x00;
g_ucIRSendSYSData2=0xBF;
g_ucIRSendCOMData1=ComData;
g_ucIRSendCOMData2=0xFF-ComData;
}
void IRSendDelay(void)
{
BYTE i=0;
for(i=0;i<200;i++)
_nop_();
}
void IRSendData(void)
{
hw_SetIRsend_Pin();
IRSendDelay();
hw_ClrIRsend_Pin();
g_ucIRSendStatus++;
if(g_ucIRSendStatus<9)
{
if(g_ucIRSendSYSData1&0x01)
g_ucIRSendCount=2;
else
g_ucIRSendCount=1;
g_ucIRSendSYSData1>>=1;
}
else if(g_ucIRSendStatus<17)
{
if(g_ucIRSendSYSData2&0x01)
g_ucIRSendCount=2;
else
g_ucIRSendCount=1;
g_ucIRSendSYSData2>>=1;
}
else if(g_ucIRSendStatus<25)
{
if(g_ucIRSendCOMData1&0x01)
g_ucIRSendCount=2;
else
g_ucIRSendCount=1;
g_ucIRSendCOMData1>>=1;
}
else if(g_ucIRSendStatus<33)
{
if(g_ucIRSendCOMData2&0x01)
g_ucIRSendCount=2;
else
g_ucIRSendCount=1;
g_ucIRSendCOMData2>>=1;
}
else
{
hw_SetIRsend_Pin();
g_bIRSendEnable=0;
}
}
void IRSendHandle(void)
{
if(g_bIRSendEnable)
{
if(g_ucIRSendCount)
g_ucIRSendCount--;
if(g_ucIRSendCount==0)
{
IRSendData();
}
}
}
#endif
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -