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

📄 ir_main.c

📁 NEC IR 控制源代码,包括接受,处理.些代码来自TV 软件开发.
💻 C
📖 第 1 页 / 共 5 页
字号:
   NOEVENT,   /* 254 */
   NOEVENT    /* 255 */
};
/* --> Last line of datablock RSTEP-Decoder in IR_MAIN.C from Mints STATE-EVENT */
#endif   /* of __RSTEP__ */



/******************************************************************************/
/**
 * GLOBAL FUNCTIONS:
 ******************************************************************************/

/******************************************************************************/
/**
 * @brief   Initialises the capture-compare-timer and buffers for IR reception.
 *          The appropriate interrupt input channel will be enabled and set to
 *          high priority.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

#ifdef __IR60__               /* infrared detection of IR60 code with TVText */
void IR_InitInfrared(void)
{

   CRT_CON0 = CRT_CON0_INIT;     /* b01010100 bit 7: OV:   clear overflow flag
                                    bit 6: PR:   2-bit prescaler
                                    bit 5: PLG:  capture enable
                                    bit 4: REL:  auto reload with capture event
                                    bit 3: RUN:  irtimer is not running, reload
                                                 & capture
                                    bit 2: RISE: capture on rising edge
                                    bit 1: FALL: capture on falling edge
                                    bit 0: SEL:  capture input select: 0 = EXT
                                                 Int.0/ 1 = EXT Int1 */

   CRT_RELL = CLOBYTE(RELOADMAXSSU);    /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSU);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSU); /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSU);

   SET_IR_INT_RISING_EDGE;              /* EXT Int. active on rising edge */

   INIT_IR_INT;

   irState = START1;                    /* init IR state */
   irActiveCounter_g = 0;

   INTSOURCE = 1;                   /* SSU is IRQ source not selected
                                                   port pin for INT0 */
   CRT_CON1 |= 0x01;                       /* bit 0: START: start SSU */
   CRT_CON0 |= 0x08;                       /* bit 3: RUN: run CRT */
}
#endif  /* of __IR60__*/



/******************************************************************************/
/**
 * @brief   Initialises the capture-compare-timer and buffers for IR reception.
 *          The appropriate interrupt input channel will be enabled and set to
 *          high priority.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

#ifdef __RC5__               /* infrared detection of RC5 code with TVText */
void IR_InitInfrared(void)
{
   CRT_CON0 = CRT_CON0_INIT;  /* b01010100  bit 7: OV:   clear overflow flag
                                  bit 6: PR:   2-bit prescaler
                                  bit 5: PLG:  capture enable
                                  bit 4: REL:  auto reload with capture event
                                  bit 3: RUN:  irtimer is not running, reload &
                                               capture
                                  bit 2: RISE: capture on rising edge
                                  bit 1: FALL: capture on falling edge
                                  bit 0: SEL:  capture input select:
                                               0 = EXT Int.0/ 1 = EXT Int1*/

   CRT_RELL = CLOBYTE(RELOADMAXSSU);       /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSU);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSU);    /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSU);

   SET_IR_INT_CHANGING_EDGE;               /* EXT Int. active edge */

   INIT_IR_INT;

   irState = START1;                       /* init IR state */
   irActiveCounter_g = 0;

   INTSOURCE = 1;         /* SSU is IRQ source not selected port pin for INT0 */

   CRT_CON1 |= 0x01;     /* bit 0: START: start SSU */
   CRT_CON0 |= 0x08;     /* bit 3: RUN: run CRT */
}
#endif  /*  __RC5__*/


#ifdef __NEC__
void IR_InitInfrared(void)/*R2000 ir protocal initialiization(peterwang 20051025)*/
{

   CRT_CON0 = CRT_CON0_INIT;     /* b01010100 
                                    bit 7: OV:   clear overflow flag
                                    bit 6: PR:   2-bit prescaler
                                    bit 5: PLG:  capture enable
                                    bit 4: REL:  auto reload with capture event
                                    bit 3: RUN:  ir timer is not running, reload
                                                 & capture
                                    bit 2: RISE: capture on rising edge
                                    bit 1: FALL: capture on falling edge
                                    bit 0: SEL:  capture input select: 0 = EXT
                                                 Int.0/ 1 = EXT Int1         */

   CRT_RELL = CLOBYTE(RELOADMAXSSU);    /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSU);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSU); /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSU);

   SET_IR_INT_FALLING_EDGE;
   
   INIT_IR_INT;

   irState = START1;                    /* init IR state */
   irActiveCounter_g = 0;

   INTSOURCE = 1;                         /* SSU is IRQ source not selected
                                              port pin for INT0 */
   CRT_CON1 |= 0x05;                     /* bit 0: START: start SSU */
   CRT_CON0 |= 0x08;                     /* bit 3: RUN: run CRT */
}
#endif




/******************************************************************************/
/**
 * @brief   Initialises the capture-compare-timer and buffers for IR reception.
 *          The appropriate interrupt input channel will be enabled and set to
 *          high priority.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

#ifdef __RSTEP__              /* infrared detection of RSTEP code */

#ifdef __RSTEP_WITH_WD_TIMER__
void IR_InitInfrared(void)
{
   WDT_CTRL = 0;      /* prescaler 2  => Fsys/24   */
   WDT_REL = 0;   /* just a value, not important! */   
   WDT_REFRESH |= 0x40; /* set timer mode and start timer*/
      
   SET_IR_INT_RISING_EDGE;

   INIT_IR_INT;

   INTSOURCE = 0;       /* port pin is IRQ source and not SSU pin for INT0 */
   WDT_REFRESH |= 0x20; /* start timer*/
   irState = START1;    /* init IR state */
   irActiveCounter_g = 0;
}

#else  /* of __RSTEP_WITH_WD_TIMER__ */
void IR_InitInfrared(void)    /* initialisation for RStep using CRT */
{
   CRT_CON0 = CRT_CON0_INIT;     /* b01010100 bit 7: OV:   clear overflow flag
                                    bit 6: PR:   2-bit prescaler
                                    bit 5: PLG:  capture enable
                                    bit 4: REL:  auto reload with capture event
                                    bit 3: RUN:  irtimer is not running, reload
                                                 & capture
                                    bit 2: RISE: capture on rising edge
                                    bit 1: FALL: capture on falling edge
                                    bit 0: SEL:  capture input select: 0 = EXT
                                                 Int.0/ 1 = EXT Int1         */

   CRT_RELL = CLOBYTE(RELOADMAXSSU);    /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSU);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSU); /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSU);

   SET_IR_INT_FALLING_EDGE;
   
   INIT_IR_INT;

   irState = START1;                    /* init IR state */
   irActiveCounter_g = 0;

   INTSOURCE = 1;                         /* SSU is IRQ source not selected
                                              port pin for INT0 */
   CRT_CON1 |= 0x01;                     /* bit 0: START: start SSU */
   CRT_CON0 |= 0x08;                     /* bit 3: RUN: run CRT */
}
#endif /* __RSTEP_WITH_WD_TIMER__ */
#endif  /* of __RSTEP__ */



/******************************************************************************/
/**
 * @brief   returns current IrState.
 *
 * @param   --
 *
 * @return  IrState
 ******************************************************************************/

uint8_t IR_GetIrState(void)
{
   return irState;
}



/******************************************************************************/
/**
 * @brief   Sets the reload values of SSU to half because clock is divided by 2
 *          in standby.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

void IR_SetSSUReloadValueToStandby(void)
{
#ifdef __IR60__
   CRT_RELL = CLOBYTE(RELOADMAXSSUSTBY);       /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSUSTBY);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSUSTBY);    /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSUSTBY);
#endif
#ifdef __RC5__
   CRT_RELL = CLOBYTE(RELOADMAXSSUSTBY);       /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSUSTBY);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSUSTBY);    /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSUSTBY);
#endif
#ifdef __NEC__
   CRT_RELL = CLOBYTE(RELOADMAXSSUSTBY);       /* max time after first event */
   CRT_RELH = CHIBYTE(RELOADMAXSSUSTBY);
   CRT_MINCAPL = CLOBYTE(RELOADMINSSUSTBY);    /* min time after first event */
   CRT_MINCAPH = CHIBYTE(RELOADMINSSUSTBY);
#endif

#ifdef __RSTEP__

#ifndef __RSTEP_WITH_WD_TIMER__
      CRT_RELL = CLOBYTE(RELOADMAXSSUSTBY);    /* max time after first event */
      CRT_RELH = CHIBYTE(RELOADMAXSSUSTBY);
      CRT_MINCAPL = CLOBYTE(RELOADMINSSUSTBY); /* min time after first event */
      CRT_MINCAPH = CHIBYTE(RELOADMINSSUSTBY);
#endif

#endif
}



/*****************************************************************************/
/**
 * @brief   Initialises spike suppression unit for IR reception.
 *
 * @param   --
 *
 * @return  --
 *****************************************************************************/

void IR_InitSsu(void)
{
   irState = START1;                       /* prepare for next IR command */

   INTSOURCE = 1;

   CRT_CON1 |= 0x01;                        /* bit 0: START: start SSU */
   CRT_CON0 &= ~0x08;                       /* bit 3: stop CRT */
   CRT_CON0 |= 0x08;                        /* bit 3: RUN: run CRT */
}




/******************************************************************************/
/**
 * @brief   Initialises spike suppression unit for IR reception.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

#ifdef  __RSTEP_WITH_WD_TIMER__
void IR_InitValues(void)
{
   irState = START1;                          /* prepare for next IR command */
   oldTimerValue = 0;
   INTSOURCE = 0;
}
#endif



/******************************************************************************/
/**
 * @brief   Decodes the infrared remote control commands, translates them into
 *          independent user commands and passes them to the message queue.
 *
 * @param   --
 *
 * @return  --
 ******************************************************************************/

#ifdef __NEC__              /* infrared detection of IR60 code with TVText */
void IR_InterruptInfrared(void)
{

uint16_t data captnew;
	uint8_t data bCom1;       // first group- 12 bits 
//	uint8_t data bCom2;       // second group- 12 bits
      uint8_t ShiftBit = 0x01;
       uint8_t n;
//       bool_t tempbit;
      	static uint8_t tmpcount = 0;	
	   captnew = (CRT_CAPH << 8) + CRT_CAPL;

//	   if ( CLK_SRC )
//	   {
//	      /* difference = real value (elapsed time since last ir event): */
//	      captnew -= RELOADMAXSSUSTBY;
//	/*      PCON &= ~BIT4;                            normal mode ( 1/1 fclock ) */
//	      captnew <<= 1;                  /* double measurement while half clock */
//	   }
	   
          captnew -= RELOADMAXSSU;
   	     if(captnew > 8000)
      {
         irState= START1;
         if(captnew > 25000)
         	;
         else
         {
            irOldCommand = 0xFFFF;
            IrOldCommandbuf = 0xFFFF;
            irMessage_g.param1 = 0;
         }
      }
	  switch(irState)
	  	{
	   case START1:
	   case 100:
	      if (( TMIN <captnew)&&(captnew < TMAX ))  // NEC: TMIN=8436   TMAX=8636
	      { 
	        SET_IR_INT_FALLING_EDGE;
	        CRT_CON1 &= 0xFE;              /** bit 0: START: stop SSU */
	        INTSRC1 = 0;  /** IRQ source is selected port pin for INT1 ( not SSU ) *//** __VCTI_TVT__*/
	        captold = 0;                /* clear half bit time */
	        irState++;                  /* prepare next state */
	        info = 0xffff;                   /* prepare new decoding */
    		 INTSOURCE = 0; /* IRQ source is selected port pin for INT0 ( not SSU ) */
		}
		if(( TREPETMIN<captnew)&&(captnew < TREPETMAX )&&(irMessage_g.param1!=0))	// (7037<TREPETMAX<7203)	
			{
            		if(systemcode != 0x10EF) return;
	       
			if ((IrOldCommandbuf == 0x02 || IrOldCommandbuf == 0x03) && OBM_IsOnDtv())
			{
				if (tmpcount >19)
				{
					info=irOldCommand;   // IrOldCommandbuf
					irState = 100;
					tmpcount = 0;
					break;
				}
				tmpcount++;
			}

			else if( ((IrOldCommandbuf == 65 ||IrOldCommandbuf == 67)&& (OBM_IsOnDtv() && DTV_State == OBM_STATUS_DTVMENU) &&  PIP_VCTP_GetPip_OnOff() == SYS_OFF))//sl
	//	else if (((IrOldCommandbuf == 65 ||IrOldCommandbuf == 67))&& (OBM_IsOnDtv() && DTV_State == OBM_STATUS_DTVMENU)) //sl
	           	{
	           	//65 left key;;;; 67 right key
				if (tmpcount >3)//5
				{
					info=irOldCommand;   // IrOldCommandbuf
					irState = 100;
					tmpcount = 0;
					break;
				}
				tmpcount++;
			}
			else if(DTV_State == OBM_STATUS_DTVMENU && (IrOldCommandbuf == 65 ||IrOldCommandbuf == 67) && PIP_VCTP_GetPip_OnOff() == SYS_ON&&OBM_IsOnDtv()&& ((bPIPMainPIC == SYS_FALSE && bPipswap ==SYS_TRUE) || (bPIPMainPIC == SYS_TRUE&& bPipswap ==SYS_FALSE)))
			{
				if (tmpcount >3)//5
				{
					info=irOldCommand;   // IrOldCommandbuf
					irState = 100;
					tmpcount = 0;
					break;
				}
				tmpcount++;
			}
		/*	else if (((IrOldCommandbuf == 65 ||IrOldCommandbuf == 67))&& (OBM_IsOnDtv() )&& (DTV_State == OBM_STATUS_MHEG5SHOW || DTV_State == OBM_STATUS_MHEG5ENTER)) //sl
			{
				if (tmpcount >=5)//10
				{
					info=irOldCommand;   // IrOldCommandbuf
					irState = 100;
					tmpcount = 0;
					break;
				}

⌨️ 快捷键说明

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