⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ir_sanyo.c

📁 主要用于液晶电视解码,内置51单片机,全部代码用C编写,编译环境为KEILC
💻 C
📖 第 1 页 / 共 2 页
字号:
/******************************************************************************
 Copyright (c) 2004 MStar Semiconductor, Inc.
 All rights reserved.

 [Module Name]: Ir.c
 [Date]:        04-Feb-2004
 [Comment]:
   Remote control subroutines.
 [Reversion History]:
*******************************************************************************/
#ifdef IR_SANYO
#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
}

//////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////
#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 repeat lead code
       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;
        }	
        // 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;
        }		
        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)
				;
                else
                    g_bIrError = 1;				
                break;
            case 13: 		  				
            #ifdef IR_DEBUG_EN
                g_ucAddresCode01 = g_ucIrDataFifo;
            #endif
                if (g_ucIrDataFifo == IR_HEADER_CODE01)
				;
                else
                    g_bIrError = 1;
                break;				
            case 21: // 2nd byte          
            #ifdef IR_DEBUG_EN
                g_ucAddresCode1 = g_ucIrDataFifo;
            #endif
                if (g_ucIrDataFifo == IR_HEADER_CODE1)
				;
                else
                    g_bIrError = 1;
                break;
            case 26: // 2nd byte
            #ifdef IR_DEBUG_EN
                g_ucAddresCode11 = g_ucIrDataFifo;
            #endif   		
                if (g_ucIrDataFifo == IR_HEADER_CODE11)
				;
                else
                    g_bIrError = 1;
                break;

				
            case 34: // 3rd byte
                g_ucDataCode = g_ucIrDataFifo;
                break;
            case 42: // 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
}
#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);

    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 repeat lead code
       if (g_bIrRepeatStatus)
        {
            // check repeat lead code
            if (g_wIrPeriodCnt > irGetMinCnt(IR_REPAEAT_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt(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;
        }	
        // check genral lead code
        if (g_wIrPeriodCnt > irGetMinCnt(IR_1ST_LEAD_TIME) && g_wIrPeriodCnt < irGetMaxCnt(IR_1ST_LEAD_TIME))
        {
            g_bIrError = 0;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -